Di-Atomic Global Docs
Docs β€Ί Chat Completions

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

model

string

yes

A task alias (spideriq/fast, spideriq/coding, spideriq/extraction, …) or a specific model id. Aliases route to the best available model. See Task Aliases.

messages

array

yes

The conversation. Each item is { "role": "system" | "user" | "assistant" | "tool", "content": string }.

max_tokens

integer

no

Maximum tokens to generate.

temperature

number

no

Sampling temperature, 0.0–2.0 (default 1.0).

top_p

number

no

Nucleus sampling, 0.0–1.0.

stop

string | array

no

Up to 4 stop sequences.

seed

integer

no

Best-effort deterministic sampling.

stream

boolean

no

If true, tokens stream back as server-sent events.

response_format

object

no

{ "type": "json_object" } for JSON mode, or { "type": "json_schema", "json_schema": { … } } for a typed schema.

tools

array

no

OpenAI-style function/tool definitions for tool calling.

tool_choice

string | object

no

"auto" (default), "none", "required", or a named function.

spidergate_options

object

no

SpiderGate extras β€” see below.

spidergate_options

Field

Type

Description

max_cost_usd

number

Hard cap on the dollar cost of this request. Exceeds β†’ the request is rejected before billing.

cache_enabled

boolean

Cache identical prompts.

cache_ttl_seconds

integer

Cache lifetime.

fallback_models

array

Extra models appended to the alias's fallback chain.

preferred_providers / excluded_providers

array

Bias or block specific providers.

timeout_ms

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

id

string

Unique completion id (chatcmpl-…).

object

string

Always chat.completion (or chat.completion.chunk when streaming).

created

integer

Unix timestamp.

model

string

The resolved provider/model that actually served the request (e.g. nvidia_nim/meta/llama-3.1-8b-instruct) β€” this is how you see which model the alias picked.

choices[]

array

Completions. Each has index, finish_reason (stop | length | tool_calls), and message {role, content, tool_calls?}.

usage

object

prompt_tokens, completion_tokens, total_tokens.

spidergate_metadata

object

SpiderGate extras β€” cost_usd (the real dollar cost of this call) and provider_model.

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 a json_schema to constrain the shape.

  • Tool calling β€” supply tools (OpenAI function definitions); when the model calls one, finish_reason is tool_calls and message.tool_calls[] carries the calls.

Errors

Error

Status

When

Resolution

invalid_api_key

401

Missing or invalid Authorization header

Send Authorization: Bearer <key>; check the key hasn't been rotated.

insufficient_quota

402

Account/credit exhausted, or max_cost_usd too low for the request

Top up credit, or raise spidergate_options.max_cost_usd.

model_not_found

404

model is not a known alias or model id

Use a valid alias (see Task Aliases) or model id from Models.

rate_limit_exceeded

429

Too many requests

Back off and retry; SpiderGate already fails over across providers, so sustained 429s mean your key's quota, not one provider.

all_providers_failed

502

Every model in the alias chain failed

Retry; widen the chain with spidergate_options.fallback_models.

Full list + handling β†’ Errors.

Last updated July 19, 2026