API reference
SpaceRouter API
One OpenAI-compatible endpoint for chat and image models. Use the OpenAI SDK you already have and change the base URL.
Make a request
Create a key in the app, then send your first request.
curl https://api.spacerouter.ai/v1/chat/completions \
-H "Authorization: Bearer $SPACEROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemini-3.1-flash-lite",
"messages": [{ "role": "user", "content": "Say hello" }]
}'Base URL
https://api.spacerouter.ai/v1
Auth
Bearer token
Format
OpenAI-compatible
The examples use google/gemini-3.1-flash-lite. Any model ID from the catalogue works in its place.
Endpoints
Paths are relative to the base URL.
| Method | Path | What it does |
|---|---|---|
GET | /models | Lists every model your key can use. |
POST | /chat/completions | Sends a chat request. Set stream to true to receive server-sent events that end with [DONE]. |
Streaming
Add "stream": true and read the response as server-sent events. Each event carries the next piece of the answer, and the stream ends with [DONE].
curl -N https://api.spacerouter.ai/v1/chat/completions \
-H "Authorization: Bearer $SPACEROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemini-3.1-flash-lite",
"messages": [{ "role": "user", "content": "Say hello" }],
"stream": true
}'
# data: {"object":"chat.completion.chunk","choices":[{"delta":{"content":"Hello"}}]}
# data: [DONE]Generate an image
Image models answer through the same chat endpoint. Ask for image output with modalities, and the picture comes back as a base64 data URL on the message. Read it at choices[0].message.images[0].image_url.url.
curl https://api.spacerouter.ai/v1/chat/completions \
-H "Authorization: Bearer $SPACEROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemini-3.1-flash-image",
"messages": [{ "role": "user", "content": "A friendly illustrated portrait of a person" }],
"modalities": ["image", "text"]
}'
# choices[0].message.images[0].image_url.url -> "data:image/png;base64,..."Authentication and errors
Send your key as a Bearer token. A missing or invalid key returns status 401 with the standard error object.
HTTP 401
{
"error": {
"message": "The API key is missing or not valid.",
"type": "invalid_request_error",
"code": "invalid_api_key",
"param": null
}
}Response headers
| Header | Meaning |
|---|---|
x-sr-cost | The cost of this request. |
x-request-id | The request’s identifier. Quote it when you contact support. |
Model IDs
IDs follow provider/model. A few forms add something to that.
| Form | Example | Meaning |
|---|---|---|
provider/model | anthropic/claude-sonnet-5.5 | A specific model. |
~provider/name-latest | ~anthropic/claude-sonnet-latest | An alias that points at the newest model of that name. |
model:batch | anthropic/claude-sonnet-5.5:batch | The batch variant of a model. |
model:free | google/gemma-4-31b-it:free | The free variant, where one is offered. |
Models
A selection from the catalogue as of 23 November 2026. GET /models lists everything your key can use, and is the source of truth.
Frontier
anthropic/claude-fable-5.2anthropic/claude-opus-5.5openai/gpt-6.1-solgoogle/gemini-3.1-pro-previewx-ai/grok-4.7moonshotai/kimi-k3.1-pro
Fast and low cost
anthropic/claude-haiku-5.5google/gemini-3.1-flash-liteopenai/gpt-5.4-nanomistralai/mistral-small-2603qwen/qwen3.8-flashdeepseek/deepseek-v4.1-flash
Open-weight families
openai/gpt-oss-120bmeta-llama/llama-3.3-70b-instructmistralai/mistral-nemogoogle/gemma-4-31b-itnvidia/nemotron-3-super-120b-a12b
Image generation
google/gemini-3.1-flash-imagegoogle/gemini-3-pro-imageopenai/gpt-5-image
Search-grounded
perplexity/sonar-pro
Limits and pricing
Rate limits depend on your plan. Prices are set per model and change, so check the pricing page and your usage dashboard rather than a table here.