Gateway
SDK
There is no Lobstack client to install. The Gateway speaks the OpenAI Chat Completions protocol, so the OpenAI SDK is the client — change the base URL and the key.
There are three packages on npm and none of them is required. The scope is
@lobstack-ai and not @lobstack; only the CLI is unscoped. Copy the name from here rather than guessing it.@lobstack-ai/mcp 0.1.0 — The Lobstack Gateway as an MCP server over stdio: route a prompt, list models, send a call, read what it cost — inside Claude Desktop, Claude Code, Cursor or Zed. Docs.@lobstack-ai/gateway 0.1.0 — A typed TypeScript client for the Lobstack Gateway, shipping the OpenAPI description and the JSON Schema for the receipt returned on every response. Docs.lobstack 0.1.1 — The Lobstack CLI: the Gateway from a terminal, with a local OpenAI-compatible proxy and the cost of each call shown as it happens. Zero dependencies. Docs.Install and construct
The base URL is https://www.lobstack.ai/api/gateway/v1. The SDK appends /chat/completions and /models to it, both of which the Gateway serves. Keys look like lsk_live_<8 hex><48 hex> and need the inference scope. Mint one in the Console.
Chat
Reading the Lobstack headers
The routing decision and the price are on the response headers, and both SDKs can hand you the raw response alongside the parsed body.
x-lobstack-cost-usd and x-lobstack-savings-usd are empty strings rather than zeros when there is no honest number — an unpriced model, or no baseline to measure against. Parse with that in mind.
The three baseline headers are sent only when a baseline exists, and they travel together. Read x-lobstack-baseline-reason before you render a saving: a plan_ceiling figure is measured against the most expensive model the plan allows, which the caller never asked for, and showing it as though they had is misreporting it. The full list is on Metering & cost.
Streaming
x_lobstack beside the usual usage object — see Metering. The chunk is sent unconditionally; you do not need stream_options.include_usage, which the Gateway does not read.$0.00 for every request the router sent to a model its copy had never heard of — next to a correct invoice. Read x_lobstack.cost_usd off the frame. It is null, never 0, when we could not price the call.A thin wrapper, if you want one
The OpenAI SDK hides the headers behind withResponse(). If you would rather have the routing and cost facts on the return value, this is the whole of it. Copy it into your codebase; there is nothing to install.
It does not handle streaming: a streamed response carries no cost headers, and the price arrives in the body of the final chunk instead, which the OpenAI SDK already parses. Use the SDK for streams and read x_lobstack off that chunk.
Listing models
Each entry carries the OpenAI fields plus label, tier, context_window, price_per_mtok and managed. The SDK will not surface those extras on its typed model object, so read them from the raw JSON when you need them. created is not returned. The full catalog is on Models & providers.
What the OpenAI SDK cannot do here
The Gateway reads a defined set of body fields and ignores the rest. The SDK will happily send the others and the request will succeed without them, which is the failure mode worth knowing about: nothing errors, the parameter just has no effect.
| Sent by the SDK | What happens |
|---|---|
| model, messages, stream, max_tokens, temperature, tools | Forwarded, subject to the per-model rules on Chat Completions. |
| top_p, tool_choice, n, stop, response_format, seed, logprobs | Dropped silently. Not forwarded, no header reports it. |
| stream_options.include_usage | Ignored. The final chunk carries usage and x_lobstack cost regardless. |
| Assistants, embeddings, images, audio, batches, files | Not implemented. The Gateway serves chat completions and a model listing. |
Client-side retries in the SDK are on by default. Read the note about duplicate billing on Errors & retries before you leave them there for expensive calls: the Gateway accepts no idempotency key, so a retried request that already completed upstream is generated and metered twice.
Other clients
Anything that speaks OpenAI
The same substitution works for any tool that lets you set an OpenAI base URL and key. Nothing about the request shape changes, so a framework that wraps the OpenAI SDK inherits the Gateway without knowing about it. What it will not inherit is the headers: a wrapper that returns only the parsed body drops the receipt, and the usage API is then the way to get the cost back.