LLM Gatewaydocs

Quick Start

Make your first request in under five minutes. The gateway exposes an OpenAI-compatible API at https://api.smartapihub.com/v1; every request is authenticated with a single API key and routed to the best available provider for the model you ask for.

1. Get an API key

  1. Sign in to the dashboard and open API Keys.
  2. Click Create key, give it a name and (optionally) limits: allowed models, allowed modalities, IP allow-list, daily/monthly budget, expiry.
  3. Copy the secret. It starts with sk-llm- and is shown exactly once — the platform stores only a SHA-256 hash.

Export it in your shell:

bash
export LLM_API_KEY="sk-llm-…"
export LLM_GATEWAY="https://api.smartapihub.com"
Keep keys secret

Never embed a key in a browser bundle or a public repository. Use a server-side proxy for browser apps. If a key leaks, rotate it in the dashboard — the old key is revoked immediately.

2. Your first chat completion

bash
curl "$LLM_GATEWAY/v1/chat/completions" \
  -H "Authorization: Bearer $LLM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-4o-mini",
    "messages": [{ "role": "user", "content": "Say hello in one sentence." }]
  }'

The response is a standard chat.completion object with two platform extensions: the provider that served it and usage.x_llm_cost_micro, the amount charged in micro-USD (1,000,000 micro-USD = $1).

json
{
  "id": "chatcmpl-8f1c…",
  "object": "chat.completion",
  "created": 1725446400,
  "model": "openai/gpt-4o-mini",
  "provider": "openai",
  "choices": [
    { "index": 0, "message": { "role": "assistant", "content": "Hello! It's great to meet you." }, "finish_reason": "stop" }
  ],
  "usage": { "prompt_tokens": 12, "completion_tokens": 9, "total_tokens": 21, "x_llm_cost_micro": 7 }
}

Look at the response headers too — they tell you which provider handled the request and why:

http
X-Request-Id: req_01J6ZK3M9PQR7S8T9V
X-LLM-Provider: openai
X-LLM-Model: openai/gpt-4o-mini
X-LLM-Routing-Reason: strategy=priority_cheapest selected=openai priority=10 cost_micro=7 healthy=true fallbacks=azure-openai
X-LLM-Cost-Micro: 7

Keep X-Request-Id when reporting an issue; it links to the request in the dashboard's Requests explorer.

3. Stream the response

Set "stream": true to receive Server-Sent Events. The gateway always emits a final chunk containing usage before data: [DONE], whether or not you pass stream_options.

bash
curl -N "$LLM_GATEWAY/v1/chat/completions" \
  -H "Authorization: Bearer $LLM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-4o-mini",
    "stream": true,
    "messages": [{ "role": "user", "content": "Count to five." }]
  }'
text
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","created":1725446400,"model":"openai/gpt-4o-mini","provider":"openai","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}

data: {"id":"chatcmpl-…","object":"chat.completion.chunk","created":1725446400,"model":"openai/gpt-4o-mini","provider":"openai","choices":[{"index":0,"delta":{"content":"1"},"finish_reason":null}]}

data: {"id":"chatcmpl-…","object":"chat.completion.chunk","created":1725446400,"model":"openai/gpt-4o-mini","provider":"openai","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: {"id":"chatcmpl-…","object":"chat.completion.chunk","created":1725446400,"model":"openai/gpt-4o-mini","provider":"openai","choices":[],"usage":{"prompt_tokens":11,"completion_tokens":13,"total_tokens":24,"x_llm_cost_micro":9}}

data: [DONE]

See Streaming for the full wire format, ping comments, error chunks and fallback rules.

4. Switch model

Model ids are vendor/name. Change one string to move to a different model — or a different vendor — without touching anything else:

bash
curl "$LLM_GATEWAY/v1/chat/completions" \
  -H "Authorization: Bearer $LLM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-3-5-haiku",
    "messages": [{ "role": "user", "content": "Say hello in one sentence." }]
  }'

List everything your key can use, with pricing and capabilities, via GET /v1/models:

bash
curl "$LLM_GATEWAY/v1/models" -H "Authorization: Bearer $LLM_API_KEY"

5. Use an official SDK

Because the wire format is OpenAI's, the official openai packages work unchanged — set the base URL and key:

typescript
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://api.smartapihub.com/v1',
  apiKey: process.env.LLM_API_KEY,
});

const completion = await client.chat.completions.create({
  model: 'openai/gpt-4o-mini',
  messages: [{ role: 'user', content: 'Say hello in one sentence.' }],
});
console.log(completion.choices[0].message.content);

Next steps