UniterRouter
API ReferenceOpenAI Compatible

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/completions

Request Body

ParameterTypeRequiredDescription
modelstringYesID of the model to use (e.g., gpt-4o, claude-3-5-sonnet-20241022)
messagesarrayYesArray of message objects with role and content
streambooleanNoEnable streaming responses (default: false)
temperaturenumberNoSampling temperature (0-2, default: 1)
max_tokensintegerNoMaximum tokens to generate
top_pnumberNoNucleus sampling parameter
toolsarrayNoList of tools/functions the model can call
tool_choicestring/objectNoControl tool selection behavior
response_formatobjectNoSpecify 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

RoleDescription
systemSets behavior and context for the assistant
userMessages from the user
assistantPrevious assistant responses
toolResults 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?