LiteRouter Docs

Making Requests

Send chat completion requests to any supported model.

Endpoint

text
POST https://api.literouter.com/v1/chat/completions

Request body

FieldTypeDescription
modelstringModel ID, e.g. glm-5.2. Required.
messagesarrayConversation so far, each with a role and content. Required.
temperaturenumberRandomness, 0-2. Optional (default 1).
max_tokensintegerMaximum tokens to generate. Optional.
streambooleanStream the response. See Streaming. Optional.

Example request

bash
curl https://api.literouter.com/v1/chat/completions \
  -H "Authorization: Bearer $LITEROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "glm-5.2",
    "messages": [
      { "role": "system", "content": "You are a helpful assistant." },
      { "role": "user", "content": "Explain what an API gateway is." }
    ],
    "temperature": 0.7
  }'
python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.literouter.com/v1",
    api_key="YOUR_LITEROUTER_API_KEY",
)

resp = client.chat.completions.create(
    model="glm-5.2",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain what an API gateway is."},
    ],
    temperature=0.7,
)
print(resp.choices[0].message.content)
javascript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.literouter.com/v1",
  apiKey: process.env.LITEROUTER_API_KEY,
});

const resp = await client.chat.completions.create({
  model: "glm-5.2",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "Explain what an API gateway is." },
  ],
  temperature: 0.7,
});
console.log(resp.choices[0].message.content);

Example response

json
{
  "id": "chatcmpl-abc123",
  "model": "glm-5.2",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "An API gateway is..." },
      "finish_reason": "stop"
    }
  ],
  "usage": { "prompt_tokens": 24, "completion_tokens": 88, "total_tokens": 112 }
}
ⓘ

The response shape follows the OpenAI Chat Completions format, so existing parsers work unchanged.