SegmindSegmind / Docs

API Reference

Authenticate with an x-api-key header and call any model on the Segmind AI Gateway over REST, with cURL and Python examples.

Authentication

Create an API key

The Segmind AI Gateway uses API keys for authentication. To create one, sign in to your account and head to the API Keys page on the dashboard.

Use the API

Pass your API key in the x-api-key request header.

An image model returns the image bytes as the response body, not JSON — so write the response to a file rather than printing it.

Example cURL request:

curl -X POST "https://api.segmind.com/v1/fast-flux-schnell" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  --output output.jpg \
  -d '{
    "prompt": "a futuristic city skyline at sunset, cinematic",
    "steps": 4,
    "aspect_ratio": "1:1"
  }'

Example Python request:

import requests

api_key = "YOUR_API_KEY"
url = "https://api.segmind.com/v1/fast-flux-schnell"

data = {
    "prompt": "a futuristic city skyline at sunset, cinematic",
    "steps": 4,
    "aspect_ratio": "1:1",
}

response = requests.post(url, json=data, headers={"x-api-key": api_key})
response.raise_for_status()

with open("output.jpg", "wb") as f:
    f.write(response.content)

Finding a model's parameters

Every model takes a different request body. To see the one you need, open the model's page and click the API tab — for example sdxl1.0-newreality-lightning. It lists every parameter the model accepts, along with example code.

Endpoints

Base URL

POST https://api.segmind.com/...

Version 1 (v1)

Some endpoints that typically complete their requests within 60 seconds are on version 1. For example: https://api.segmind.com/v1/sdxl1.0-newreality-lightning

Version 2 (v2)

We created v2 to serve APIs that typically take longer than 60 seconds to process.

API error codes

The status codes you are most likely to see from the gateway:

CodeStatusMeaningBilled?
200OKRequest completed successfully and output was produced.Yes
400Bad RequestThe request could not be processed — a malformed body, a missing required field, or an operation the model does not support.No
401UnauthorizedAuthentication failed. Check your API key.No
403ForbiddenThe model exists, but your account or team is not permitted to call it.No
404Not FoundNo such model endpoint, or no such request ID.No
405Method Not AllowedWrong HTTP verb — the model routes take POST. Returns HTML, not JSON.No
406Not AcceptableMost often a missing or wrong Content-Type. Also: your balance is below the model's cost, a parameter value was rejected up front, or a team spend limit has been reached.No
422UnprocessableOn v2, the inference itself failed.No
429Too Many RequestsRate limit exceeded. Retry after a short delay.No
500Server ErrorAn internal server error occurred during processing.No

A few of these are easy to misread, so they are worth spelling out:

  • The most common 406 has nothing to do with credits. Send a request with no Content-Type, or one that is not application/json or multipart/form-data, and you get 406 with "Invalid content type". Some HTTP clients omit the header when a body is passed as a plain string, so this is easy to hit by accident and easy to misdiagnose as a billing problem.
  • 406 also covers credits and limits. Your balance being below the model's cost, a parameter value rejected before the model runs — an unsupported duration or resolution, say — and a member hitting a team spend limit, which returns a message naming the period and the cap.
  • Not every bad parameter is a 406. Values are checked up front only where the model declares a fixed set; anything else reaches the model and fails during generation, which surfaces as a 500. So a 500 on a request you have only just changed is worth re-reading as a parameter problem before assuming the platform is broken.
  • 405 is the one response that is not JSON. Every other error returns {"error": …}; a wrong verb returns an HTML error page. A client that calls .json() on every response without checking the status will throw here rather than report the real problem.
  • 403 is a permission decision, not a bad request. Retrying will not help; the model is restricted for your team, or it is private to another account. See model restrictions.
  • 422 on v2 means the job ran and failed, not that your request body was wrong — the response carries a status of FAILED and an error describing what went wrong. See Async inference.

Billing note: you are charged only for requests that return HTTP 200. Every error response rolls the credit reservation back in full. See Billing logic for how the reservation system works.

On this page