Chat Completions
Create a model response for a conversation. SpiderGate is OpenAI-compatible, so this is the same shape as OpenAI's Chat Completions β plus SpiderGate routing (model accepts a task alias) and spidergate_options.
POST /chat/completions
Authentication β Authorization: Bearer <API key> (details).
Request body
Field | Type | Required | Description |
|---|---|---|---|
| string | yes | A task alias ( |
| array | yes | The conversation. Each item is |
| integer | no | Maximum tokens to generate. |
| number | no | Sampling temperature, |
| number | no | Nucleus sampling, |
| string | array | no | Up to 4 stop sequences. |
| integer | no | Best-effort deterministic sampling. |
| boolean | no | If |
| object | no |
|
| array | no | OpenAI-style function/tool definitions for tool calling. |
| string | object | no |
|
| object | no | SpiderGate extras β see below. |
spidergate_options
Field | Type | Description |
|---|---|---|
| number | Hard cap on the dollar cost of this request. Exceeds β the request is rejected before billing. |
| boolean | Cache identical prompts. |
| integer | Cache lifetime. |
| array | Extra models appended to the alias's fallback chain. |
| array | Bias or block specific providers. |
| integer | Per-request timeout. |
Example request
cURL
curl https://spideriq.ai/api/gate/v1/chat/completions \
-H "Authorization: Bearer $SPIDERGATE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "spideriq/fast",
"messages": [
{ "role": "system", "content": "You are a concise assistant." },
{ "role": "user", "content": "In one sentence, what is an LLM gateway?" }
],
"max_tokens": 60,
"spidergate_options": { "max_cost_usd": 0.01 }
}'Python (drop-in OpenAI SDK β just change base_url)
from openai import OpenAI
client = OpenAI(
api_key=os.environ["SPIDERGATE_API_KEY"],
base_url="https://spideriq.ai/api/gate/v1",
)
resp = client.chat.completions.create(
model="spideriq/fast",
messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "In one sentence, what is an LLM gateway?"},
],
max_tokens=60,
)
print(resp.choices[0].message.content)JavaScript (fetch)
const res = await fetch("https://spideriq.ai/api/gate/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.SPIDERGATE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "spideriq/fast",
messages: [{ role: "user", content: "In one sentence, what is an LLM gateway?" }],
max_tokens: 60,
}),
});
const data = await res.json();
console.log(data.choices[0].message.content);Response
A chat.completion object (real response from the call above):
{
"id": "chatcmpl-721027d3a2444b09a1769d21",
"object": "chat.completion",
"created": 1784494387,
"model": "nvidia_nim/meta/llama-3.1-8b-instruct",
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": "An LLM (Large Language Model) gateway is a software interface that enables other applications or services to access and utilize the capabilities of a large language model, such as natural language processing and generation, in a secure and scalable manner."
}
}
],
"usage": { "prompt_tokens": 52, "completion_tokens": 47, "total_tokens": 99 }
}Response fields
Field | Type | Description |
|---|---|---|
| string | Unique completion id ( |
| string | Always |
| integer | Unix timestamp. |
| string | The resolved provider/model that actually served the request (e.g. |
| array | Completions. Each has |
| object |
|
| object | SpiderGate extras β |
Streaming
Set "stream": true to receive chat.completion.chunk events as server-sent events, each carrying a choices[].delta fragment. The stream ends with data: [DONE].
JSON mode & tool calling
JSON mode β
"response_format": { "type": "json_object" }forces valid JSON; pass ajson_schemato constrain the shape.Tool calling β supply
tools(OpenAI function definitions); when the model calls one,finish_reasonistool_callsandmessage.tool_calls[]carries the calls.
Errors
Error | Status | When | Resolution |
|---|---|---|---|
|
| Missing or invalid | Send |
|
| Account/credit exhausted, or | Top up credit, or raise |
|
|
| Use a valid alias (see Task Aliases) or model id from Models. |
|
| Too many requests | Back off and retry; SpiderGate already fails over across providers, so sustained 429s mean your key's quota, not one provider. |
|
| Every model in the alias chain failed | Retry; widen the chain with |
Full list + handling β Errors.