Skip to content

Chat Completions

Generate text with any text model available on ImageRouter. This endpoint is OpenAI Chat Completions compatible — point the OpenAI SDK at ImageRouter by changing the base URL and you are done. You are billed on the true token cost of each request.

Terminal window
curl 'https://api.imagerouter.io/v1/openai/chat/completions' \
-H 'Authorization: Bearer YOUR_API_KEY' \
--json '{
"model": "openai/gpt-4o-mini",
"messages": [
{ "role": "user", "content": "Write a haiku about the ocean." }
]
}'

Set stream: true to receive a Server-Sent Events stream. The stream is proxied unchanged, and the final chunk carries token usage and the true cost.

Terminal window
curl 'https://api.imagerouter.io/v1/openai/chat/completions' \
-H 'Authorization: Bearer YOUR_API_KEY' \
--json '{
"model": "openai/gpt-4o-mini",
"messages": [{ "role": "user", "content": "Write a haiku about the ocean." }],
"stream": true
}'
  • model required Text model to use for the completion.

  • messages required List of messages in the conversation, in OpenAI Chat Completions format. Each message has a role (system, user, assistant, or tool) and content.

  • stream optional When true, partial deltas are streamed as Server-Sent Events. Defaults to false.

  • temperature, max_tokens, top_p, tools, tool_choice, response_format, reasoning_effort, … optional All standard OpenAI Chat Completions parameters are passed through to the model unchanged.

{
"id": "chatcmpl-...",
"object": "chat.completion",
"created": 1234567890,
"model": "openai/gpt-4o-mini",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "..." },
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 24,
"total_tokens": 36,
"cost": 0.0000123
},
"cost": 0.0001
}

usage.cost is the true upstream cost in USD. The top-level cost field is what was charged to your ImageRouter credits (the true cost, rounded up to the nearest 1/10,000 USD).