API details
Base API URL
All API endpoints in the reference documentation are relative to the following base URL:
Authentication
For any request you make when communicating with Merge Gateway, you will need an API key to authenticate yourself as an authorized user.
Add your API Key with a “Bearer ” prefix as a header called Authorization to authorize your Merge API requests. This header must be included in every request in this format:
You do not have to use the dashboard to get a key. The Management API mints, rotates, and revokes API keys programmatically, which is what you want if keys are provisioned per customer or checked into infrastructure-as-code.
Key endpoints
Gateway’s model-calling surface is centered around these endpoint groups:
GET /models: List models, filter byproviderorvendor, or fetch a single model with?model=<provider/model_id>GET /vendors: List execution vendors and the models they currently serve, or fetch one withGET /vendors/{vendor_id}POST /responses: Create an LLM response in Gateway’s native Responses shape. The response includes thevendorthat ultimately served the request and theservice_tierthat actually served it.POST /chat/completions: Create a chat completion in the OpenAI wire formatPOST /messages: Create a message in the Anthropic wire format, withPOST /messages/count_tokensto count input tokens without calling a modelPOST /embeddings: Create embeddings, priced on input tokens
Gateway also exposes SDK-compatible surfaces under /v1/openai, /v1/anthropic, /v1/ai-sdk, and /v1/langchain, so an existing client reaches the same models with a base URL change. The OpenAI and Anthropic wire formats are additionally served at their vendor-default paths: POST /v1/chat/completions (OpenAI SDK pointed at https://api-gateway.merge.dev/v1) and POST /v1/messages plus /v1/messages/count_tokens (Anthropic SDK pointed at https://api-gateway.merge.dev). Both forms accept the same requests. See Get started.
/v1/responses is Gateway's native API, not OpenAI's Responses API
The two share a URL suffix and accept the same request body, but they return different shapes: the native endpoint streams response.stream / response.done snapshots, while OpenAI’s Responses API streams response.created … response.completed events. Clients that implement OpenAI’s Responses API — the OpenAI SDK’s client.responses.*, Codex, and similar harnesses — belong on the /v1/openai base URL. See Responses below for what happens when such a client reaches the native endpoint anyway.
Administering the org, rather than calling models, is a separate surface: see Management API below.
Management API
API keys, projects, routing policies, and usage are administered programmatically through the Management API, on the same host. It is authenticated by a management key (Authorization: Bearer mgmt_<your_management_key>) rather than a gateway API key, so the credential that provisions keys is never one that can make model calls. Create a management key in the dashboard under API keys → Management keys.
Full reference and scopes: Management API. Walkthroughs: API keys and Projects API.
Models API shape
GET /models returns canonical model identity at the top level and vendor-specific execution metadata under vendors.
Example:
Use GET /models?model=<provider/model_id> when you want one specific model object but prefer a query parameter over a path parameter. The slash is fine there because it is part of the query parameter value.
Vendors API shape
GET /vendors returns execution hosts, not canonical model owners.
Example:
Pagination
GET /models and GET /vendors return a paged list envelope:
limit sets the page size. It defaults to 50 and caps at 500. A higher value is rejected before the request reaches the catalog:
Do not size a single request to the catalog. The catalog grows as models are added, so a limit that fits today silently starts truncating later. Page instead: send the previous response’s next_cursor back as cursor and keep going while has_more is true. The next page starts after the cursor entry, so pages never overlap, and next_cursor is null on the last page. Treat the cursor as opaque, a value to pass back rather than one to construct.
Filters do not carry across pages on their own, so repeat provider or vendor on every request in the loop alongside cursor. Fetching one model with ?model=<provider/model_id> returns a bare model object rather than a list envelope, so it has no has_more or next_cursor.
The Management API paginates separately and caps its list endpoints at 100 per page: GET /v1/keys takes offset and limit and reports has_more, and GET /v1/projects takes cursor and limit.
Responses
POST /responses returns the canonical model that served the request and a top-level vendor field for the execution host that actually handled it.
Request parameters
Beyond the message input, the request accepts these optional fields:
OpenAI Responses API clients
POST /responses speaks Gateway’s native shape. OpenAI’s Responses API is served at POST /openai/responses, and that is where OpenAI-wire clients (the OpenAI SDK’s client.responses.*, Codex) should point. Three behaviors keep a client that reaches the native endpoint by mistake from failing silently:
- Codex is served the OpenAI shape automatically. Codex tags every request with an
originator: codex_*header; aPOST /v1/responsescarrying it is served byPOST /v1/openai/responses, so Codex works whether its base URL ends in/v1or/v1/openai. The documented base URL is still/v1/openai. X-Merge-Wire-Formatselects the shape explicitly.X-Merge-Wire-Format: openaionPOST /v1/responsesreturns the OpenAI Responses shape for any caller;X-Merge-Wire-Format: nativepins the native shape and overrides the Codex detection. Any other endpoint ignores the header.- OpenAI-only request fields are translated, not dropped. On the native endpoint,
instructionsbecomes a leadingsystemmessage,reasoning.effortis applied as the reasoning effort for the route that serves the request,text.formatbecomesresponse_format, andmax_output_tokensis an alias ofmax_tokens. An explicit native field wins over its OpenAI counterpart (thinkingoverreasoning,response_formatovertext.format).parallel_tool_callsis accepted without effect. Any other OpenAI-only field (truncation,include,background,prompt_cache_key, …) is ignored and reported in the response’swarningswith codeopenai_fields_ignored, so a misrouted client can see which settings did not apply:
On streaming requests the warning rides on the final response.done chunk. An unknown reasoning.effort level or a malformed text.format is rejected with 400, exactly as on POST /openai/responses.
Served tier and billing
The response echoes a top-level service_tier: the tier that actually served the request and the rate you were billed at. On a throttle fallback this differs from the tier you sent (e.g. you requested flex but were served and billed at standard).
See Service tiers for the full flow, supported vendor routes, and fallback behavior.
Per-call cost
Every response carries usage.cost: the provider cost in USD that Gateway computed for that call, from the tokens above and the pricing of the route that actually served the request. No request parameter is needed.
usage.cost is returned on:
Three details worth knowing:
costisnull, never0, when the served route has no pricing on file. A false zero would be recorded as real spend by anything summing costs, so an unknown price is reported as unknown. Cost-tracking tools that read this field, such as Langfuse, skip a null instead of logging $0.- It is the same figure as
routing.cost_usd, which is only returned when you setinclude_routing_metadata: true. Both come from the same calculation, so a request that asks for both sees them agree. Useusage.costfor everyday cost tracking and routing metadata when you also need the policy and vendor decisions behind the call. - It is provider cost, not your invoiced amount. The two can differ, and the invoice is the authority. Billing starts from this figure and then applies your organization’s plan rate, prices BYOK requests against the model’s list price rather than what your own provider account charged, and adds server-tool charges such as web search, which never appear in
usage.cost.
Cost reflects the tier that served the request, so a flex request that fell back to standard is priced at standard. For invoiced spend, budgets, and dashboards, see Cost governance and savings.