SegmindSegmind / Docs
Use Cases

Build a Text-to-Image API

Build a text-to-image API without writing model code: wire a prompt input to an image model in PixelFlow, publish it, and call your endpoint from any app.

The fastest way to put image generation behind your own API: build the pipeline visually, publish it, and call it from your app. You get a stable endpoint you control — swap models or add steps later without changing a line of caller code.

Build the workflow

Wire prompt → model → output

Create a workflow with a text input node, an image model, and an output node — the full walkthrough is in build your first workflow.

Name the API fields

Set the input node's key name to prompt and the output node's to image. Those become your API's request and response fields.

Publish

Click Publish — you get a versioned endpoint and code samples. Details in publish as an API.

Call it from code

import os, time, json, requests

headers = {"Authorization": f"Bearer {os.environ['SEGMIND_API_KEY']}"}

submit = requests.post(
    "https://api.segmind.com/workflows/v2/<your-workflow-slug>",
    headers=headers,
    json={"prompt": "a lighthouse at dusk, dramatic sky"},
).json()

while True:
    s = requests.get(submit["poll_url"], headers=headers).json()
    if s["status"] in ("COMPLETED", "FAILED"):
        break
    time.sleep(3)

result = requests.get(submit["response_url"], headers=headers).json()
print(result["images"][0]["url"])

Full request/response shapes, JavaScript and cURL versions, and error handling are in the API reference.

Why a workflow instead of calling the model directly?

You can call any single model via the Serverless API. A workflow earns its keep when the endpoint should be yours:

  • Swap models without breaking callers — re-publish with a different model behind the same contract.
  • Add steps invisibly — bolt an upscaler or safety checker onto the pipeline; callers still send prompt, get image.
  • Encode your defaults — style prefixes via text concatenation, fixed negative prompts, tuned parameters — baked into the workflow, not duplicated across client code.
  • Constrain inputs — dropdown inputs publish as enumerated parameters, so callers can only send valid values.

Variations

  • Style presets — a dropdown input (photographic, anime, watercolor) concatenated into the prompt.
  • Prompt enhancement — an LLM node rewrites the user's prompt before the image model sees it.
  • Batch generation — accept an array and fan out to generate per item.

On this page