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. |
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].
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.
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