Skip to content
Fresh 2026

Get started

How to send your first LLM request using the Merge Gateway SDK, OpenAI SDK, or Vercel AI SDK.

Merge Gateway is the control plane for production AI. Access all LLMs through 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. Get one from the Merge Gateway dashboard.

Merge Gateway SDK

bash
pip install merge-gateway-python
bash
npm install merge-gateway-sdk
python
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)
typescript
import { MergeGateway } from "merge-gateway-sdk";

const client = new MergeGateway({ apiKey: "YOUR_API_KEY" });

const response = await 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." },
  ],
});

console.log(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, pass project_id in the request body.

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

python
response = client.responses.create(
    model="anthropic/claude-sonnet-4-20250514",
    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."},
    ],
)
python
response = client.responses.create(
    model="google/gemini-2.0-flash",
    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.

python
from openai import OpenAI

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

const client = new OpenAI({
  apiKey: "YOUR_API_KEY",
  baseURL: "https://api-gateway.merge.dev/v1/openai",
});

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

python
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)
typescript
const response = await 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." },
  ],
});

console.log(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.

bash
npm install merge-gateway-ai-sdk-provider ai
typescript
import { createMergeGateway } from "merge-gateway-ai-sdk-provider";

const gateway = createMergeGateway({
  apiKey: "YOUR_API_KEY",
});

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-4o"),
  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, 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
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
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
python
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="claude-sonnet-4-20250514",
    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

Configure intelligent routing, failover, and cost optimization across providers

Automatically reduce token usage and avoid context window limits

Explore the full Gateway API

Unofficial documentation reference. Built for internal use.