Skip to main content
POST
/
v1
/
chat
/
completions
POST /v1/chat/completions
curl --request POST \
  --url https://api.geekhub.mx/v1/chat/completions \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "<string>",
  "messages": [
    {
      "role": {},
      "content": "<string>",
      "name": "<string>"
    }
  ],
  "temperature": 123,
  "top_p": 123,
  "max_tokens": 123,
  "stream": true,
  "stop": [
    "<string>"
  ]
}
'
{
  "id": "<string>",
  "object": "<string>",
  "created": 123,
  "model": "<string>",
  "choices": [
    {
      "index": 123,
      "message.role": "<string>",
      "message.content": "<string>",
      "finish_reason": "<string>"
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123
  }
}

Request body

model
string
required
The namespaced model ID, e.g. anthropic/claude-sonnet-4-6. See Chat models.
messages
array
required
Conversation messages.
temperature
number
default:"varies by model"
Between 0 and 2. Higher = more creative, lower = more deterministic.
top_p
number
Between 0 and 1. Nucleus sampling. Alternative to temperature.
max_tokens
integer
Maximum tokens to generate. Default varies by model.
stream
boolean
default:"false"
If true, responds with Server-Sent Events. See Streaming section below.
stop
string | string[]
Sequences that end generation.

Response (non-streaming)

id
string
Your request_id (format req_<24hex>). Useful for tracing.
object
string
Always "chat.completion".
created
integer
Unix timestamp.
model
string
The namespaced model id (e.g. anthropic/claude-sonnet-4-6).
choices
array
Array with a single element (n > 1 not supported yet).
usage
object
Tokens consumed. Charged at request completion.

Streaming

For real-time responses, send "stream": true. You’ll receive Server-Sent Events:
data: {"id":"req_xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}

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

data: {"id":"req_xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" world"},"finish_reason":null}]}

data: {"id":"req_xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]
Each data: is a JSON with a delta.content that is the next text fragment (can be a word, a syllable, or even a single character).

TypeScript parser

const res = await fetch("https://api.geekhub.mx/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.GEEKHUB_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "anthropic/claude-haiku-4-5",
    messages: [{ role: "user", content: "Count to 5" }],
    stream: true,
  }),
});

const reader = res.body!.getReader();
const decoder = new TextDecoder();
let buffer = "";

while (true) {
  const { value, done } = await reader.read();
  if (done) break;
  buffer += decoder.decode(value, { stream: true });

  let nl: number;
  while ((nl = buffer.indexOf("\n\n")) !== -1) {
    const block = buffer.slice(0, nl);
    buffer = buffer.slice(nl + 2);
    const data = block.split("\n").find(l => l.startsWith("data:"))?.slice(5).trim();
    if (!data || data === "[DONE]") continue;
    const chunk = JSON.parse(data);
    process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
  }
}

Examples per provider

response = client.chat.completions.create(
    model="anthropic/claude-sonnet-4-6",
    messages=[
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": "Capital of Mexico?"}
    ],
    max_tokens=200,
)

Common errors

See Errors for the full catalog. The most frequent in chat:
  • 400 invalid_request_error — malformed body (Zod tells you the field in message)
  • 402 insufficient_balance — no balance
  • 404 model_not_found — invalid model id (probably missing namespace)
  • 502 provider_unavailable — provider bounced (sometimes it’s a rejected prompt)