AI Integration

Machine-readable schemas and tool definitions for AI agents, IDEs, and automated systems.

Available Schemas

TheRouter.ai publishes API schemas in multiple formats. All files are served from /ai/ and auto-generated from source code annotations.

NameTypeRequiredDescription
/ai/mcp.json
MCP ServerModel Context Protocol server specification with tool definitions for chat_completion, list_models, and get_credits.
/ai/openai-functions.json
OpenAI FunctionsFunction calling definitions compatible with OpenAI's tools parameter format.
/ai/anthropic-tools.json
Anthropic ToolsTool definitions compatible with Claude's tool_use / input_schema format.
/ai/openapi.json
OpenAPI 3.1Full OpenAPI specification with rich examples for each endpoint.
/ai/therouter-types.d.ts
TypeScriptTypeScript type definitions with JSDoc comments for editor intellisense and AI context.

MCP Server Configuration

Point any MCP-compatible client at the TheRouter.ai specification:

mcp-config.json
{
  "mcpServers": {
    "therouter": {
      "url": "https://therouter.ai/ai/mcp.json",
      "env": {
        "THEROUTER_API_KEY": "sk-or-your-key"
      }
    }
  }
}

OpenAI Function Calling

Load function definitions and pass them to any OpenAI-compatible client:

typescript
const res = await fetch("https://therouter.ai/ai/openai-functions.json");
const spec = await res.json();

const response = await openai.chat.completions.create({
  model: "openai/gpt-4o",
  messages: [{ role: "user", content: "Check my credit balance" }],
  tools: spec.functions,
});

Anthropic Tool Use

Load tool definitions for Claude's Messages API:

python
import httpx, anthropic

spec = httpx.get("https://therouter.ai/ai/anthropic-tools.json").json()

response = anthropic.Anthropic().messages.create(
    model="claude-sonnet-4-5-20250514",
    max_tokens=1024,
    tools=spec["tools"],
    messages=[{"role": "user", "content": "List available models"}],
)

Auto-Generation

All schemas are generated from src/types.ts annotations using a single command:

bash
npm run generate-ai-schemas

This reads the gateway source types and produces all schema files in docs/public/ai/. Run it after modifying API types to keep schemas in sync.

Schema Versioning
Schema files are regenerated on each docs build. Pin to a specific commit or release tag if your integration requires a stable schema version.