LLM Gatewaydocs

Migrating from OpenAI

The gateway implements the OpenAI wire format, so migrating an existing integration is a configuration change, not a rewrite. Three things change:

  1. Base URLhttps://api.smartapihub.com/v1
  2. API key → your sk-llm-… key from the dashboard
  3. Model id → prefixed with the vendor: gpt-4o-mini becomes openai/gpt-4o-mini

Before / after

typescript
import OpenAI from 'openai';

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

const res = await client.chat.completions.create({
  model: 'openai/gpt-4o-mini', // was 'gpt-4o-mini'
  messages: [{ role: 'user', content: 'Hello' }],
});

Model id mapping

OpenAI idGateway id
gpt-4oopenai/gpt-4o
gpt-4o-miniopenai/gpt-4o-mini
text-embedding-3-smallopenai/text-embedding-3-small
dall-e-3openai/dall-e-3
tts-1openai/tts-1
whisper-1openai/whisper-1

The exact set of available models depends on what your operator has enabled; always check GET /v1/models. Once migrated, switching to another vendor is one string: anthropic/claude-3-5-haiku, meta/llama-3.1-70b-instruct, and so on — the request shape stays the same.

What is the same

  • Request and response bodies for chat completions, completions, embeddings, images, speech and transcriptions.
  • SSE streaming format, including data: [DONE].
  • Tool calling (tools, tool_choice, tool_calls), response_format (json_object, json_schema), seed, penalties, logit_bias, stop.
  • Error envelope shape: { "error": { "type", "code", "message", "param" } }.

What is different

AreaDifference
nOnly n: 1 is supported.
usageAlways present on non-streaming responses and always emitted as a final stream chunk — you no longer need stream_options.include_usage. Contains x_llm_cost_micro and, when estimated, x_llm_usage_estimated: true.
providerExtra top-level field on responses naming the provider that served the request.
routingOptional request extension to override routing per request. Stripped before forwarding.
HeadersX-Request-Id, X-LLM-Provider, X-LLM-Model, X-LLM-Routing-Reason, X-LLM-Cost-Micro on every inference response.
Errorserror.code uses the gateway's code enum, and error.request_id is always present.
Video / musicAsync job endpoints (202 + polling / webhooks) that do not exist in the OpenAI API. Idempotency-Key is required.
Responses APISupported as a documented subset.
Fine-tuning, files, assistants, batches, realtimeNot provided by the gateway.

Checklist

  • Replace base URL and key.
  • Prefix model ids with the vendor.
  • Remove any code that assumes n > 1.
  • Read usage.x_llm_cost_micro instead of computing cost client-side.
  • Log X-Request-Id alongside your own request logs.
  • Handle 402 (credits/budget) in addition to 429 — see API Keys.