Chat Completions
OpenAI Chat Completions API - Create GPT-4, GPT-3.5 chat completions through UniterRouter. Compatible with OpenAI SDK, supports streaming and function calling.
Chat Completions
Create a model response for a chat conversation. This is the primary endpoint for interacting with LLMs.
Endpoint
POST https://api.uniterouter.ai/v1/chat/completionsRequest Body
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | ID of the model to use (e.g., gpt-4o, claude-3-5-sonnet-20241022) |
messages | array | Yes | Array of message objects with role and content |
stream | boolean | No | Enable streaming responses (default: false) |
temperature | number | No | Sampling temperature (0-2, default: 1) |
max_tokens | integer | No | Maximum tokens to generate |
top_p | number | No | Nucleus sampling parameter |
tools | array | No | List of tools/functions the model can call |
tool_choice | string/object | No | Control tool selection behavior |
response_format | object | No | Specify output format (e.g., JSON) |
Messages Format
{
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"},
{"role": "assistant", "content": "Hi! How can I help you?"},
{"role": "user", "content": "What's the weather like?"}
]
}Message Roles
| Role | Description |
|---|---|
system | Sets behavior and context for the assistant |
user | Messages from the user |
assistant | Previous assistant responses |
tool | Results from tool/function calls |
Example Request
curl https://api.uniterouter.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $UNITEROUTER_API_KEY" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
}'from openai import OpenAI
client = OpenAI(
base_url="https://api.uniterouter.ai/v1",
api_key="your_api_key",
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
)
print(response.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.uniterouter.ai/v1",
apiKey: process.env.UNITEROUTER_API_KEY,
});
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Hello!" },
],
});
console.log(response.choices[0].message.content);Response
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1699000000,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 10,
"total_tokens": 30
}
}Streaming
Enable streaming to receive responses token-by-token:
stream = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")See Streaming Guide for more details.
Supported Models
UniterRouter supports 200+ models from all major providers:
- OpenAI: gpt-4o, gpt-4-turbo, gpt-3.5-turbo
- Anthropic: claude-3-5-sonnet, claude-3-opus, claude-3-haiku
- Google: gemini-2.0-flash, gemini-1.5-pro
- DeepSeek: deepseek-chat, deepseek-reasoner
- And many more...
See the full list at www.uniterouter.ai/models.
How is this guide?
OpenAI Compatible
OpenAI API proxy - Use GPT-4, GPT-4o, GPT-3.5-turbo with existing OpenAI SDK. Drop-in replacement for ChatGPT API with access to 200+ LLM models.
Streaming
OpenAI Streaming API - Real-time GPT-4, Claude responses with Server-Sent Events. Implement streaming chat, reduce time-to-first-token for better UX in AI applications.