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>"
]
}
'import requests
url = "https://api.geekhub.mx/v1/chat/completions"
payload = {
"model": "<string>",
"messages": [
{
"role": {},
"content": "<string>",
"name": "<string>"
}
],
"temperature": 123,
"top_p": 123,
"max_tokens": 123,
"stream": True,
"stop": ["<string>"]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
messages: [{role: {}, content: '<string>', name: '<string>'}],
temperature: 123,
top_p: 123,
max_tokens: 123,
stream: true,
stop: ['<string>']
})
};
fetch('https://api.geekhub.mx/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.geekhub.mx/v1/chat/completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'messages' => [
[
'role' => [
],
'content' => '<string>',
'name' => '<string>'
]
],
'temperature' => 123,
'top_p' => 123,
'max_tokens' => 123,
'stream' => true,
'stop' => [
'<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.geekhub.mx/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"role\": {},\n \"content\": \"<string>\",\n \"name\": \"<string>\"\n }\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"max_tokens\": 123,\n \"stream\": true,\n \"stop\": [\n \"<string>\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.geekhub.mx/v1/chat/completions")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"role\": {},\n \"content\": \"<string>\",\n \"name\": \"<string>\"\n }\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"max_tokens\": 123,\n \"stream\": true,\n \"stop\": [\n \"<string>\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.geekhub.mx/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"role\": {},\n \"content\": \"<string>\",\n \"name\": \"<string>\"\n }\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"max_tokens\": 123,\n \"stream\": true,\n \"stop\": [\n \"<string>\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"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
}
}Chat
POST /v1/chat/completions
Generación de respuestas de chat con cualquier modelo
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>"
]
}
'import requests
url = "https://api.geekhub.mx/v1/chat/completions"
payload = {
"model": "<string>",
"messages": [
{
"role": {},
"content": "<string>",
"name": "<string>"
}
],
"temperature": 123,
"top_p": 123,
"max_tokens": 123,
"stream": True,
"stop": ["<string>"]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
messages: [{role: {}, content: '<string>', name: '<string>'}],
temperature: 123,
top_p: 123,
max_tokens: 123,
stream: true,
stop: ['<string>']
})
};
fetch('https://api.geekhub.mx/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.geekhub.mx/v1/chat/completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'messages' => [
[
'role' => [
],
'content' => '<string>',
'name' => '<string>'
]
],
'temperature' => 123,
'top_p' => 123,
'max_tokens' => 123,
'stream' => true,
'stop' => [
'<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.geekhub.mx/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"role\": {},\n \"content\": \"<string>\",\n \"name\": \"<string>\"\n }\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"max_tokens\": 123,\n \"stream\": true,\n \"stop\": [\n \"<string>\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.geekhub.mx/v1/chat/completions")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"role\": {},\n \"content\": \"<string>\",\n \"name\": \"<string>\"\n }\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"max_tokens\": 123,\n \"stream\": true,\n \"stop\": [\n \"<string>\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.geekhub.mx/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"role\": {},\n \"content\": \"<string>\",\n \"name\": \"<string>\"\n }\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"max_tokens\": 123,\n \"stream\": true,\n \"stop\": [\n \"<string>\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"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
string
required
El ID namespaced del modelo, ej.
anthropic/claude-sonnet-4-6. Ver Modelos chat.array
required
number
default:"varía por modelo"
Entre 0 y 2. Más alto = más creativo, más bajo = más determinista.
number
Entre 0 y 1. Nucleus sampling. Alternativa a
temperature.integer
Máximo de tokens a generar. Default varía por modelo.
boolean
default:"false"
Si
true, responde con Server-Sent Events. Ver sección Streaming abajo.string | string[]
Sequencias que terminan la generación.
Response (non-streaming)
string
Tu
request_id (formato req_<24hex>). Útil para tracing.string
Siempre
"chat.completion".integer
Unix timestamp.
string
El model id namespaced (e.g.
anthropic/claude-sonnet-4-6).array
Streaming
Para responses en tiempo real, manda"stream": true. Recibirás 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":"Hola"},"finish_reason":null}]}
data: {"id":"req_xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" mundo"},"finish_reason":null}]}
data: {"id":"req_xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]
data: es un JSON con un delta.content que es el siguiente fragmento del texto (puede ser una palabra, una sílaba, hasta un solo caracter).
Parser TypeScript
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: "Cuenta hasta 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 ?? "");
}
}
Ejemplos por proveedor
response = client.chat.completions.create(
model="anthropic/claude-sonnet-4-6",
messages=[
{"role": "system", "content": "Eres un asistente conciso."},
{"role": "user", "content": "¿Capital de México?"}
],
max_tokens=200,
)
response = client.chat.completions.create(
model="openai/gpt-5",
messages=[{"role": "user", "content": "Explica QPS en una línea"}],
)
response = client.chat.completions.create(
model="google/gemini-2.5-pro",
messages=[{"role": "user", "content": "Hola"}],
temperature=0.5,
)
response = client.chat.completions.create(
model="deepseek/deepseek-v4-pro",
messages=[{"role": "user", "content": "Resuelve: 23 * 17 paso a paso"}],
)
Errores comunes
Ver Errores para el catálogo completo. Los más frecuentes en chat:400 invalid_request_error— body mal formado (Zod te dice el campo enmessage)402 insufficient_balance— sin saldo404 model_not_found— model id inválido (probablemente le faltó namespace)502 provider_unavailable— el provider rebotó (a veces es prompt rechazado)
⌘I