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:
| Code | Status | Meaning | Billed? |
|---|---|---|---|
| 200 | OK | Request completed successfully and output was produced. | Yes |
| 400 | Bad Request | The request could not be processed — a malformed body, a missing required field, or an operation the model does not support. | No |
| 401 | Unauthorized | Authentication failed. Check your API key. | No |
| 403 | Forbidden | The model exists, but your account or team is not permitted to call it. | No |
| 404 | Not Found | No such model endpoint, or no such request ID. | No |
| 405 | Method Not Allowed | Wrong HTTP verb — the model routes take POST. Returns HTML, not JSON. | No |
| 406 | Not Acceptable | Most 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 |
| 422 | Unprocessable | On v2, the inference itself failed. | No |
| 429 | Too Many Requests | Rate limit exceeded. Retry after a short delay. | No |
| 500 | Server Error | An internal server error occurred during processing. | No |
A few of these are easy to misread, so they are worth spelling out:
- The most common
406has nothing to do with credits. Send a request with noContent-Type, or one that is notapplication/jsonormultipart/form-data, and you get406with "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. 406also covers credits and limits. Your balance being below the model's cost, a parameter value rejected before the model runs — an unsupporteddurationorresolution, 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 a500. So a500on a request you have only just changed is worth re-reading as a parameter problem before assuming the platform is broken. 405is 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.403is 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.422on v2 means the job ran and failed, not that your request body was wrong — the response carries astatusofFAILEDand anerrordescribing 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.