Get started

Send your first request through Merge Gateway

Merge Gateway is a unified API for large language models. Route requests to OpenAI, Anthropic, Google, and AWS Bedrock through a single endpoint — with built-in failover, intelligent routing, cost optimization, and observability.

You’ll need a Merge Gateway API key. Get one from the Merge Gateway dashboard.

Merge Gateway SDK

1

Install the SDK

$pip install merge-gateway-sdk
2

Send a request

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

Try a different model

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

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

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

1from openai import OpenAI
2
3client = OpenAI(
4 api_key="YOUR_API_KEY",
5 base_url="https://api-gateway.merge.dev/v1/openai",
6)
2

Send a request

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

1response = client.chat.completions.create(
2 model="gpt-5.2",
3 messages=[
4 {"role": "system", "content": "You are a helpful programming tutor. Explain the concepts clearly with practical examples."},
5 {"role": "user", "content": "Explain the concept of recursion in programming with a simple set of examples."},
6 ],
7)
8
9print(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
1import { createMergeGateway } from "merge-gateway-ai-sdk-provider";
2
3const gateway = createMergeGateway({
4 apiKey: "YOUR_API_KEY",
5});
3

Send a request

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

TypeScript
1import { generateText } from "ai";
2
3const { text } = await generateText({
4 model: gateway("openai/gpt-4o"),
5 prompt: "Explain the concept of recursion in programming with a simple set of examples.",
6});
7
8console.log(text);

The native provider gives you typed access to Gateway features like tags, vendor routing, and routing metadata via providerOptions.mergeGateway.

Alternative: URL shim (no extra install)

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

TypeScript
1import { createOpenAI } from "@ai-sdk/openai";
2
3const gateway = createOpenAI({
4 apiKey: "YOUR_API_KEY",
5 baseURL: "https://api-gateway.merge.dev/v1/ai-sdk",
6});
7
8// 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
Anthropichttps://api-gateway.merge.dev/v1/anthropic
AI SDK (Vercel)https://api-gateway.merge.dev/v1/ai-sdk
LangChainhttps://api-gateway.merge.dev/v1/openai
Anthropic SDK
1from anthropic import Anthropic
2
3client = Anthropic(
4 api_key="YOUR_API_KEY",
5 base_url="https://api-gateway.merge.dev/v1/anthropic",
6)
7
8message = client.messages.create(
9 model="claude-sonnet-4-20250514",
10 max_tokens=1024,
11 messages=[
12 {"role": "user", "content": "Explain the concept of recursion in programming with a simple set of examples."},
13 ],
14)
15
16print(message.content[0].text)

Next steps