For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Logo
Resources
Log inGet a demo
GuidesModelsAPI reference
GuidesModelsAPI reference
    • Get started
    • Install skills
  • Features
    • Projects
    • Cost governance and savings
    • Tool calling
    • Web search
    • Context compression
      • Overview
      • Cursor
      • Zed
      • Continue.dev
      • OpenCode
      • Claude Code
      • Codex
  • Security & Compliance
    • Customer blocklist
    • Geo-location routing
    • Prompt injection protection
    • Data loss prevention
    • Audit trail
    • Roles and permissions
    • Zero data retention
    • Provider terms

Get started

  • Overview
  • Introduction
  • Unified API
  • Linked Account
  • Merge Link
  • Use cases

Implementation

  • Sandboxes
  • SDKs
  • API access
  • Syncing data
  • Writing data
  • Data minimization
  • Supplemental data
  • Errors
  • Integration metadata

API reference

  • ATS
  • HRIS
  • Accounting
  • Ticketing
  • CRM
  • File Storage
  • Knowledge Base
  • Chat

Resources

  • Help Center
  • Merge.dev
  • Changelog
© Merge 2026Terms of usePrivacy policy
UnifiedAgent HandlerGateway
UnifiedAgent HandlerGateway
Resources
Log inGet a demo
On this page
  • Before you start
  • Configure OpenCode
  • Caveats
  • Next steps
FeaturesBuilding with coding agents

OpenCode

Add Merge Gateway as a provider in OpenCode to use any model with a single API key
Was this page helpful?
Previous

Continue.dev

Next

Claude Code

OpenCode is an open-source terminal coding agent. Add Merge Gateway as a provider and OpenCode can use every model Gateway supports through a single API key, with routing policies, cost governance, and full request observability in the Gateway dashboard.

Before you start

  • Install OpenCode: npm i -g opencode-ai or brew install anomalyco/tap/opencode

  • Grab an API key from gateway.merge.dev/settings/api-keys and export it:

    $export MERGE_GATEWAY_API_KEY="mg_your_key"
  • Decide which models fit your workflow. Gateway model names take the form provider/model, for example anthropic/claude-sonnet-4-6 for heavy coding or google/gemini-2.5-flash for fast, low-cost edits. Browse the full catalog with GET /v1/models or in the dashboard.

Configure OpenCode

1

Add Merge Gateway to opencode.json

Create an opencode.json in your project root (or ~/.config/opencode/opencode.json):

1{
2 "$schema": "https://opencode.ai/config.json",
3 "provider": {
4 "merge-gateway": {
5 "npm": "merge-gateway-ai-sdk-provider",
6 "name": "Merge Gateway",
7 "options": {
8 "baseURL": "https://api-gateway.merge.dev/v1/ai-sdk",
9 "apiKey": "{env:MERGE_GATEWAY_API_KEY}"
10 },
11 "models": {
12 "anthropic/claude-sonnet-4-6": { "name": "Claude Sonnet 4.6" },
13 "google/gemini-2.5-flash": { "name": "Gemini 2.5 Flash" }
14 }
15 }
16 }
17}

These two cover a common pair: a high-capability model for hard problems, and a fast, low-cost model for quick edits. Add whichever models fit your use case. Each key is a Gateway provider/model name from GET /v1/models.

2

Launch OpenCode and pick a model

Run opencode in your project, then /models and select one of your Merge Gateway models.

3

Send a test message

Ask OpenCode to make a small code change. Streaming, tool calls, and file edits all work, and the request shows up in your Gateway dashboard within a few seconds.

Caveats

Declaring models in opencode.json

Until Merge Gateway is listed in OpenCode’s model registry, declare the models you want under the models key above. Once Gateway is in the registry, you can run /connect, select Merge Gateway, paste your key, and skip the models block.

Let Gateway choose the model

Instead of hard-picking a model, point at a routing policy and let Gateway select the vendor and model per request based on your rules (cost, performance, or prompt complexity). Useful when you want cheap models for simple edits and stronger models for hard problems without switching by hand.

Persisting the configuration

The export MERGE_GATEWAY_API_KEY=... above lives in your shell, so it applies only to that terminal. To persist it, add the same line to your shell profile (~/.zshrc, ~/.bashrc, or ~/.config/fish/config.fish). The opencode.json itself is committed to your project, so it persists across sessions automatically.

Tool calling

OpenCode is agentic and relies on tool calls to read and edit files. Tool calling works through Gateway for any model whose capabilities.supports_tool_calling is true on the chosen vendor route. See Tool calling.

Which models can I use?

Any model Gateway supports. Use GET /v1/models to list them, or open the Gateway dashboard and copy the model identifier.

Next steps

Routing policies

Let Gateway pick the best vendor for each OpenCode request

Projects

Use a project-scoped key so OpenCode usage is tracked separately

Cost governance

Cap spend and restrict which models OpenCode can hit