Search Documentation

Search for pages and headings in the documentation

Chat Completions

Generate model responses for a conversation. This is the primary endpoint for text generation with crimson-falcon-4, indigo-owl-4, and amber-phoenix-4.

Endpoint

POST /v1/chat/completions

Request body

ParameterTypeRequiredDescription
modelstringYesModel ID (e.g., crimson-falcon-4).
messagesarrayYesArray of message objects.
temperaturefloatNoSampling temperature (0-2). Default: 1.0.
top_pfloatNoNucleus sampling. Default: 1.0.
max_tokensintNoMax tokens to generate.
streamboolNoStream partial responses via SSE. Default: false.
stopstring/arrayNoStop sequence(s).
nintNoNumber of completions. Default: 1.

Message object

FieldTypeRequiredDescription
rolestringYessystem, user, or assistant.
contentstringYesThe message content.

Example request

curl https://api.liutong.llby.org/v1/chat/completions \
  -H "Authorization: Bearer lt_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "crimson-falcon-4",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Explain quantum entanglement in simple terms."}
    ],
    "temperature": 0.7,
    "max_tokens": 512
  }'

Response

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1700000000,
  "model": "crimson-falcon-4",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Quantum entanglement is..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 150,
    "total_tokens": 175
  }
}

Streaming

Set stream: true to receive partial responses as server-sent events (SSE):

curl https://api.liutong.llby.org/v1/chat/completions \
  -H "Authorization: Bearer lt_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "crimson-falcon-4",
    "messages": [{"role": "user", "content": "Hello!"}],
    "stream": true
  }'

Each SSE event contains a chunk:

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}

data: [DONE]

Error responses

StatusDescription
401Invalid or missing API key.
400Malformed request body.
404Model not found.
429Rate limit exceeded.
500Internal server error.