Get started

Send your first request through Merge Gateway

Merge Gateway puts every LLM behind a single API, with intelligent routing, cost management, and security built in. Route to OpenAI, Anthropic, Google, and AWS Bedrock through a single endpoint, with automatic failover and observability.

You’ll need a Merge Gateway API key. Sign up and take one from the Merge Gateway dashboard, or mint one programmatically with the Management API if you provision a key per customer or per environment.

Signing up needs no card. The free plan comes with credit to spend on its model list, and paid traffic is the provider’s price for the tokens plus a 5% Merge fee. Plans and pricing covers the rest.

Merge Gateway SDK

1

Install the SDK

pip install merge-gateway-python
2

Send a request

from merge_gateway import MergeGateway
client = MergeGateway(api_key="YOUR_API_KEY")
response = client.responses.create(
model="openai/gpt-5.2",
input=[
{"type": "message", "role": "system", "content": "You are a helpful programming tutor. Explain the concepts clearly with practical examples."},
{"type": "message", "role": "user", "content": "Explain the concept of recursion in programming with a simple set of examples."},
],
)
print(response.output[0].content[0].text)

If you have a routing policy configured (on a project or as the org default), the model field is optional. The policy picks the provider and model. Either omit model or set it to the sentinel value "default_routing" to explicitly hand off to your policy. To scope a request to a project, use a project API key or pass project_id in the request body; see Projects.

3

Try a different model

Swap the model string to route to a different provider. No other code changes needed.

response = client.responses.create(
model="anthropic/claude-sonnet-5",
input=[
{"type": "message", "role": "system", "content": "You are a helpful programming tutor. Explain the concepts clearly with practical examples."},
{"type": "message", "role": "user", "content": "Explain the concept of recursion in programming with a simple set of examples."},
],
)

OpenAI SDK

Already using the OpenAI SDK? Point it at Merge Gateway to get multi-provider routing without changing your application code.

1

Point to Gateway

from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api-gateway.merge.dev/v1/openai",
)

https://api-gateway.merge.dev/v1 works too. That form matches the OpenAI SDK’s default base URL shape, so the only change from https://api.openai.com/v1 is the host.

2

Send a request

Use the standard chat.completions.create method. No provider prefix needed on the model name.

response = client.chat.completions.create(
model="gpt-5.2",
messages=[
{"role": "system", "content": "You are a helpful programming tutor. Explain the concepts clearly with practical examples."},
{"role": "user", "content": "Explain the concept of recursion in programming with a simple set of examples."},
],
)
print(response.choices[0].message.content)

AI SDK (Vercel)

Using the Vercel AI SDK? Use the Merge Gateway provider for full access to routing, tags, and cost tracking, or use the quick-start URL shim for zero-install setup.

1

Install packages

npm install merge-gateway-ai-sdk-provider ai
2

Create the provider

TypeScript
import { createMergeGateway } from "merge-gateway-ai-sdk-provider";
const gateway = createMergeGateway({
apiKey: "YOUR_API_KEY",
});
3

Send a request

Use generateText to send a request. Model names use the provider/model format.

TypeScript
import { generateText } from "ai";
const { text } = await generateText({
model: gateway("openai/gpt-5.5"),
prompt: "Explain the concept of recursion in programming with a simple set of examples.",
});
console.log(text);

The native provider gives you typed access to Gateway features like tags, vendor routing, routing metadata, and structured-output strict control via providerOptions.mergeGateway. generateObject and streamObject map to Gateway’s native json_schema structured output — see Structured outputs.

On AI SDK v5? Import from the /v5 subpath instead — same package, same options, adapted to the v5 provider spec:

import { createMergeGateway } from "merge-gateway-ai-sdk-provider/v5";

AI SDK v6 uses the root import shown above. AI SDK v4 is not supported by the native provider — use the URL shim below.

Alternative: URL shim (no extra install)

If you already have @ai-sdk/openai installed, point it at Gateway with a base URL change:

TypeScript
import { createOpenAI } from "@ai-sdk/openai";
const gateway = createOpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://api-gateway.merge.dev/v1/ai-sdk",
});
// All generateText/streamText calls work unchanged

Other SDKs

Gateway is compatible with any SDK that lets you set a custom base URL.

SDKBase URL
OpenAIhttps://api-gateway.merge.dev/v1/openai or https://api-gateway.merge.dev/v1
Anthropichttps://api-gateway.merge.dev/v1/anthropic or https://api-gateway.merge.dev
AI SDK (Vercel)https://api-gateway.merge.dev/v1/ai-sdk
LangChainhttps://api-gateway.merge.dev/v1/openai

Where two base URLs are listed, both accept the same requests. The second is each SDK’s default base URL shape: the OpenAI SDK appends chat/completions to a /v1 base URL, and the Anthropic SDK appends /v1/messages to the host, so the only change from the vendor’s own base URL is the host. Two exceptions: the OpenAI SDK’s client.responses.* at the /v1 base URL reaches /v1/responses, which is Gateway’s native Responses API rather than OpenAI’s, so use the /v1/openai base URL when you call the Responses API; and the Anthropic SDK’s models.list() at the bare host returns Gateway’s native model listing, so use the /v1/anthropic base URL if you need Anthropic-shaped model listings.

Anthropic SDK
from anthropic import Anthropic
client = Anthropic(
api_key="YOUR_API_KEY",
base_url="https://api-gateway.merge.dev/v1/anthropic",
)
message = client.messages.create(
model="anthropic/claude-sonnet-5",
max_tokens=1024,
messages=[
{"role": "user", "content": "Explain the concept of recursion in programming with a simple set of examples."},
],
)
print(message.content[0].text)

Next steps