#Coding Tools

The gateway speaks both API dialects, so agentic coding tools work out of the box — point the tool's base URL at the gateway and hand it your OpenRouter key. Verified end-to-end (full agent loops with tool use): Claude Code, opencode, cline.

New here? Start with the User Guide for auth and the model catalog.

#Claude Code

Quick one-off via environment variables:

export ANTHROPIC_BASE_URL="https://api.badlandslabs.com"
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
export ANTHROPIC_API_KEY=""   # must be explicitly empty
claude -p "Reply with exactly one word: PONG" --output-format json

Or make it permanent in ~/.claude/settings.json (or a project's .claude/settings.json) with an env block:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.badlandslabs.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-or-v1-YOUR-OPENROUTER-KEY",
    "ANTHROPIC_API_KEY": "",
    "ANTHROPIC_MODEL": "@preset/auto",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "@preset/auto",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "@preset/auto",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "@preset/auto",
    "CLAUDE_CODE_AUTO_COMPACT_WINDOW": "1000000"
  }
}

What each variable does:

Variable Purpose
ANTHROPIC_BASE_URL Points Claude Code at the gateway (bare base URL, no /v1)
ANTHROPIC_AUTH_TOKEN Your OpenRouter key, sent as a Bearer token
ANTHROPIC_API_KEY Set to empty string so a leftover Anthropic key doesn't conflict
ANTHROPIC_MODEL Default model card for the session (any id from the catalog works)
ANTHROPIC_DEFAULT_SONNET_MODEL / _OPUS_MODEL / _HAIKU_MODEL What the sonnet / opus / haiku aliases resolve to — Claude Code also uses the haiku slot for background tasks
CLAUDE_CODE_AUTO_COMPACT_WINDOW Token threshold before Claude Code auto-compacts history; 1000000 suits large-context presets

Tips:

#opencode

opencode can talk to the gateway in either dialect — pick the provider package that matches the flavor you want (or configure both side by side; each is verified working). Drop this in opencode.json at your project root (or merge into your global config):

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "badlands": {
      "npm": "@ai-sdk/anthropic",
      "name": "Badlands Gateway (Anthropic dialect)",
      "options": {
        "baseURL": "https://api.badlandslabs.com/v1",
        "apiKey": "{env:OPENROUTER_API_KEY}"
      },
      "models": { "claude-sonnet-5": { "name": "Badlands (Anthropic flavor)" } }
    },
    "badlands-oai": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Badlands Gateway (OpenAI dialect)",
      "options": {
        "baseURL": "https://api.badlandslabs.com/v1",
        "apiKey": "{env:OPENROUTER_API_KEY}"
      },
      "models": { "gpt-5.6-sol": { "name": "Badlands (OpenAI flavor)" } }
    }
  }
}
# Anthropic flavor (hits /v1/messages)
opencode run -m "badlands/claude-sonnet-5" "your task"

# OpenAI flavor (hits /v1/chat/completions)
opencode run -m "badlands-oai/gpt-5.6-sol" "your task"

The models map is yours to fill — any id from the model catalog works as an entry.

#cline

Use cline's OpenAI-compatible provider:

cline auth -p openai -b https://api.badlandslabs.com/v1 -k "$OPENROUTER_API_KEY" -m "gpt-4o"
cline "your task"          # headless one-shot (each task is a full multi-turn agent loop)
cline -i                   # interactive TUI for ongoing conversations / resuming sessions

Why not cline's Anthropic provider? The cline CLI only supports custom base URLs for its OpenAI / OpenAI-compatible providers (cline auth -p anthropic -b ... is rejected: "base URL is only supported for OpenAI and OpenAI-compatible providers"), so its native Anthropic provider always calls Anthropic directly and can't reach the gateway. The OpenAI-compatible path above is fully verified — multi-turn agent loops, tool use, and file edits all work.

Tip for OpenAI-dialect clients: the gateway forces "reasoning": {"exclude": true} upstream, then removes any returned <think>/reasoning text and known provider/model identity before the response reaches the client.