Chat Completions
POST /v1/chat/completions is the general-purpose LLM endpoint. Send a list of
messages, choose a model, and receive an OpenAI-shaped assistant response. LLM
API resolves the model to a provider, applies project policies such as routing,
caching, and guardrails, then normalizes the provider response. Set
stream: true to receive the answer as server-sent events (SSE).
Quick start
curl -X POST "https://api.llmapi.ai/v1/chat/completions" \
-H "Authorization: Bearer $LLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "Explain embeddings in one sentence."}]
}'
The response follows the OpenAI Chat Completions shape: read the answer from
choices[0].message.content and usage from usage.
{
"id": "chatcmpl_abc123",
"object": "chat.completion",
"model": "gpt-4o-mini",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "Embeddings are..." },
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 18,
"completion_tokens": 12,
"total_tokens": 30
}
}
Request shape
model and messages are required. A message can contain plain text or
multimodal content such as image URLs, depending on the selected model.
| Field |
Description |
model |
Model ID or a provider/model name for provider pinning. |
messages |
Ordered conversation messages. Use system, developer, user, assistant, and tool messages as supported by the model. |
max_tokens / max_completion_tokens |
Upper bound for generated output. Use the parameter accepted by the selected model. |
temperature, top_p |
Sampling controls; supported ranges are model-dependent. |
stream |
Return SSE deltas instead of one JSON response. |
response_format |
Request text, JSON object, or a JSON Schema response where supported. |
tools, tool_choice |
Enable function/tool calling where supported. |
reasoning_effort, no_reasoning |
Control reasoning models where supported. |
web_search, web_search_options |
Enable web search for models and projects that support it. |
cache_control |
Opt in to provider prompt caching; see prompt caching. |
service_tier |
"flex" runs the request at OpenAI's slower, cheaper flex tier; see flex processing. Other string values are ignored. |
Multimodal input
Vision-capable models accept the OpenAI content-array format:
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "What is in this image?" },
{
"type": "image_url",
"image_url": { "url": "https://example.com/photo.jpg" }
}
]
}
]
}
Use the Models catalog to confirm vision, audio_input,
video_input, tools, reasoning, and structured-output capabilities before
using them.
Streaming
Streaming responses use text/event-stream. Each data: event contains a
JSON chunk whose text is usually in choices[0].delta.content; the stream ends
with data: [DONE].
If the provider fails after the stream has started, the stream ends with an
error chunk instead of data: [DONE], and OpenAI SDKs raise an error. When the
provider closes the connection before the response finishes, or sends nothing
for 300 seconds, the chunk's error.code is upstream_disconnected or
stream_timeout; other provider errors use streaming_error:
data: {"error":{"message":"The upstream provider closed the stream before the response completed. Please retry.","type":"stream_error","param":null,"code":"upstream_disconnected"}}
The request log records these streams as errors. Retry the request; output
received before the error is incomplete.
curl -N -X POST "https://api.llmapi.ai/v1/chat/completions" \
-H "Authorization: Bearer $LLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"stream": true,
"messages": [{"role":"user","content":"Write a haiku about APIs."}]
}'
When you need usage in a stream, request it with
stream_options: { "include_usage": true } if the selected model supports
that option. Tool calls and reasoning content may arrive in separate delta
fields rather than content.
Flex processing
Set service_tier to "flex" to run a request at OpenAI's flex processing
tier. Flex requests are slower and may wait for capacity, and their tokens are
billed at OpenAI's flex rate, currently half the standard price. Use flex for
evaluations, background jobs and other work that does not need a fast answer.
{
"model": "gpt-5",
"service_tier": "flex",
"messages": [{ "role": "user", "content": "Summarize this report." }]
}
- Only OpenAI serves flex. A flex request is routed only to OpenAI, and
fallback never moves it to another provider or to the standard tier. When the
model cannot reach OpenAI (a model only another provider serves, a
provider/model pin on another provider, or "model": "auto"), the request
fails with 400, param: "service_tier", code: "unsupported_value", unless a
region or access rule refuses it first. Send it without service_tier to run
it at the standard tier. OpenAI decides which of its models accept flex and
answers with its own error for the others.
- You pay for the tier that served the request. The response reports it in
service_tier. Tokens are billed at the flex rate only when it is "flex";
request and web-search fees are unchanged.
- Allow up to 15 minutes. The gateway gives a flex response up to 15 minutes
to arrive, and a flex stream up to 15 minutes between events, unless a
fallback policy sets a shorter deadline or per-target
timeout. Raise your client's timeout to match.
- No capacity. When OpenAI has no flex capacity it answers
429 with
code: "flex_unavailable". The gateway returns it without retrying or trying
another provider or the standard tier, and no tokens are billed. Retry later
with backoff, or resend without service_tier.
Routing and compatibility
- Use the Models page or
GET /v1/models to find models and capabilities.
- You can pin a provider with a
provider/model model name, or configure routing and fallback.
- The optional
X-LLMAPI-Region header accepts eu, us, ap, or global for providers with native multi-region routing.
- Vision, audio input, video input, image generation, web search, and tool calling depend on the selected model. See Vision, Audio Input, and Web Search.
- Output guardrails that validate complete JSON responses cannot inspect an incomplete streaming response. Use non-streaming mode when a complete structured result must be validated.
- For generated images returned inside a chat response, see Image Generation. For dedicated image generation and editing, use Images.
API operation: POST /v1/chat/completions