Documentation

    Everything you need to integrate GateRouter into your application.

    Quick Start

    The fastest way to get started depends on your setup.

    Already using OpenClaw? One command gets you auto-routing, skills store, and x402 payments — zero config.

    # Step 1: Install the GateRouter skill
    npx openclaw add gaterouter
    
    # Step 2: Set your API key in .env
    GATEROUTER_API_KEY=your-gaterouter-api-key
    
    # Step 3: Use it in your agent — routing, skills, x402 all work automatically
    import { Agent } from "openclaw";
    
    const agent = new Agent({
      skills: ["gaterouter"],  // That's it! Auto-routing enabled.
    });
    
    const result = await agent.run("Analyze BTC market trends");
    console.log(result.output);

    What skill.md configures

    The skill manifest is bundled automatically when you install. It acts as the single source of truth for provider configuration:

    Registers GateRouter as an LLM provider
    Enables smart model routing (auto mode)
    Activates x402 crypto payment protocol
    Connects to the Skills Store catalog
    Sets default rate limits & retry policy
    Auto-updates when new models are added

    Installed file structure

    your-project/
    ├── skills/
    │   └── gaterouter/
    │       ├── skill.md          # Manifest — provider, routing, x402
    │       ├── index.ts          # Skill entry point
    │       └── config.json       # Overridable settings
    └── .env                      # GATEROUTER_API_KEY lives here

    Compatible SDKs

    Python (openai)
    Node.js (openai)
    Go
    Rust
    curl
    LangChain
    LlamaIndex
    OpenClaw

    If your SDK supports OpenAI, it works with GateRouter. No special client or wrapper needed.

    OpenClaw Agent Framework

    Partner

    Build AI agents with smart auto-routing. Set model: "auto" to let GateRouter pick the best model.

    import { Agent } from "openclaw";
    
    const agent = new Agent({
      llm: {
        provider: "openai-compatible",
        baseURL: "https://api.gaterouter.ai/v1",
        apiKey: process.env.GATEROUTER_API_KEY,
        model: "auto",  // Smart router picks the best model
      },
      skills: ["web-search", "code-interpreter"],
    });
    
    const result = await agent.run(
      "Analyze the latest BTC market trends"
    );
    console.log(result.output);

    LangChain

    Use GateRouter as a drop-in replacement for OpenAI in LangChain.

    from langchain_openai import ChatOpenAI
    
    llm = ChatOpenAI(
        base_url="https://api.gaterouter.ai/v1",
        api_key="your-gaterouter-api-key",
        model="auto",
    )
    
    response = llm.invoke("What's the weather in Tokyo?")
    print(response.content)

    Tip: Setting model: "auto" enables GateRouter's smart routing, which picks the best model based on the task, your feedback history, and cost optimization.

    API Reference

    Base URL

    https://api.gaterouter.ai/v1

    Authentication

    Include your API key in the Authorization header:

    Authorization: Bearer your-gaterouter-api-key

    Endpoints

    POST
    /v1/chat/completionsChat completions (streaming supported)
    GET
    /v1/modelsList available models
    POST
    /v1/embeddingsText embeddings

    Custom Headers

    GateRouter supports optional headers for advanced routing and features.

    x-skillsweb-searchEnable specific skills (comma-separated)
    x-402-enabledtrueEnable x402 on-chain payment flow
    x-route-preferencecost | speed | qualityHint for model routing preference
    x-gaterouter-titleMyAppApp name for analytics (optional)
    // Example: Enable web search skill with speed preference
    const response = await client.chat.completions.create({
      model: "auto",
      messages: [{ role: "user", content: "What happened today?" }],
    }, {
      headers: {
        "x-skills": "web-search",
        "x-route-preference": "speed",
      },
    });

    On-chain Payment (x402)

    New

    x402 is an HTTP-native payment protocol that lets AI agents pay for API calls using on-chain stablecoins — no pre-funded account needed.

    How It Works

    1. Send a request with x-402-enabled: true
    2. If no balance, GateRouter returns HTTP 402 with payment details
    3. Your agent signs a stablecoin transaction and retries with proof
    4. GateRouter verifies on-chain and processes the request
    // x402 payment flow
    const response = await fetch("https://api.gaterouter.ai/v1/chat/completions", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "x-402-enabled": "true",
      },
      body: JSON.stringify({
        model: "gpt-4o",
        messages: [{ role: "user", content: "Hello!" }],
      }),
    });
    
    if (response.status === 402) {
      const paymentDetails = await response.json();
      // { network, token, amount, recipient, ... }
      // Sign tx → retry with proof header
    }

    Supported Networks

    Ethereum
    Base
    Gate Layer
    Arbitrum
    Polygon
    Optimism

    Skills Store

    Extend your API with plugins and MCP tool integrations. Enable them in your dashboard or per-request via headers.

    Plugin
    Web Search

    Augment responses with real-time web search results

    Plugin
    Response Healing

    Auto-fix malformed JSON responses from LLMs

    MCP
    Gate Skills

    Official Gate exchange skills — trading, market data, portfolio

    Enable via request header:

    // Enable web search skill
    const response = await client.chat.completions.create({
      model: "gpt-4o",
      messages: [{ role: "user", content: "What happened today?" }],
    }, {
      headers: { "x-skills": "web-search" },
    });