### Run OpenClaw Setup Wizard Source: https://openrouter.ai/docs/cookbook/coding-agents/openclaw-integration Initiates the interactive setup wizard to configure OpenClaw, guiding users through provider selection, API key entry, model choice, and messaging channel setup. ```bash openclaw onboard ``` -------------------------------- ### Set up Node.js Project and Install OpenRouter SDK Source: https://openrouter.ai/docs/cookbook/get-started/quickstart This snippet initializes a new Node.js project, sets the package type to module, and installs the OpenRouter client SDK along with 'tsx' for running TypeScript examples. ```bash mkdir openrouter-chat && cd openrouter-chat npm init -y npm pkg set type=module npm install @openrouter/sdk npm install --save-dev tsx ``` -------------------------------- ### Tool Calling Example: Basic Setup Source: https://openrouter.ai/docs/guides/features/tool-calling Initializes the OpenRouter client or prepares the API request with necessary credentials and defines the initial messages for a tool-calling conversation. ```typescript import { OpenRouter } from '@openrouter/sdk'; const OPENROUTER_API_KEY = "{{API_KEY_REF}}"; // You can use any model that supports tool calling const MODEL = "{{MODEL}}"; const openRouter = new OpenRouter({ apiKey: OPENROUTER_API_KEY, }); const task = "What are the titles of some James Joyce books?"; const messages = [ { role: "system", content: "You are a helpful assistant." }, { role: "user", content: task, } ]; ``` ```python import json, requests from openai import OpenAI OPENROUTER_API_KEY = f"{{API_KEY_REF}}" # You can use any model that supports tool calling MODEL = "{{MODEL}}" openai_client = OpenAI( base_url="https://openrouter.ai/api/v1", api_key=OPENROUTER_API_KEY, ) task = "What are the titles of some James Joyce books?" messages = [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": task, } ] ``` ```typescript const response = await fetch('https://openrouter.ai/api/v1/chat/completions', { method: 'POST', headers: { Authorization: `Bearer {{API_KEY_REF}}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ model: '{{MODEL}}', messages: [ { role: 'system', content: 'You are a helpful assistant.' }, { role: 'user', content: 'What are the titles of some James Joyce books?', }, ], }), }); ``` -------------------------------- ### Manual Setup for Agent-Driven OpenRouter Provisioning Source: https://openrouter.ai/docs/guides/overview/stripe-projects Complete these steps manually before starting an agent session to avoid browser pop-ups during agent-driven provisioning of OpenRouter. ```bash stripe login stripe projects link openrouter stripe projects billing add # only if you plan to use pay-as-you-go ``` -------------------------------- ### Quick Start: Send and Log Chat Response with OpenRouter TypeScript SDK Source: https://openrouter.ai/docs/agent-sdk/typescript/overview A complete quick start example demonstrating client initialization, sending a chat message, and logging the response content. ```typescript import OpenRouter from '@openrouter/sdk'; const client = new OpenRouter({ apiKey: process.env.OPENROUTER_API_KEY }); const response = await client.chat.send({ model: "minimax/minimax-m2", messages: [ { role: "user", content: "Hello!" } ] }); console.log(response.choices[0].message.content); ``` -------------------------------- ### Send Chat Request with OpenRouter Go SDK Source: https://openrouter.ai/docs/client-sdks/go This quickstart example demonstrates how to initialize the SDK and send a basic chat message using the OpenRouter API. ```go package main import ( "context" "log" "os" openrouter "github.com/OpenRouterTeam/go-sdk" "github.com/OpenRouterTeam/go-sdk/models/components" ) func main() { ctx := context.Background() s := openrouter.New( openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")), ) res, err := s.Chat.Send(ctx, components.ChatRequest{ Messages: []components.ChatMessages{ components.CreateChatMessagesUser( components.ChatUserMessage{ Content: components.CreateChatUserMessageContentStr( "What is the capital of France?", ), Role: components.ChatUserMessageRoleUser, }, ), }, }, nil) if err != nil { log.Fatal(err) } if res != nil { // handle response } } ``` -------------------------------- ### ApplyPatchCreateFileOperation Example (YAML) Source: https://openrouter.ai/docs/api/api-reference/betaresponses/create-a-response Example schema for creating a new file in a patch operation. ```yaml path: /src/main.ts type: create_file ``` -------------------------------- ### Start OpenCode and connect to OpenRouter interactively Source: https://openrouter.ai/docs/cookbook/coding-agents/opencode-integration Navigate to your project directory and start OpenCode, then use the interactive commands to connect to OpenRouter and select models. ```bash cd /path/to/your/project opencode ``` ```text /connect ``` ```text /models ``` -------------------------------- ### OpenAPI Specification for Get Generation Content Source: https://openrouter.ai/docs/api/api-reference/generations/get-stored-prompt-and-completion-content-for-a-generation This YAML defines the OpenAPI specification for the GET /generation/content endpoint, detailing its parameters, responses, and example payloads. ```yaml openapi: 3.1.0 info: contact: email: support@openrouter.ai name: OpenRouter Support url: https://openrouter.ai/docs description: OpenAI-compatible API with additional OpenRouter features license: name: MIT url: https://opensource.org/licenses/MIT title: OpenRouter API version: 1.0.0 servers: - description: Production server url: https://openrouter.ai/api/v1 x-speakeasy-server-id: production security: - apiKey: [] tags: - description: API key management endpoints name: API Keys - description: Analytics and usage endpoints name: Analytics - description: Anthropic Messages endpoints name: Anthropic Messages - description: BYOK endpoints name: BYOK - description: Benchmarks endpoints name: Benchmarks - description: Chat completion endpoints name: Chat - description: Task classification market-share endpoints name: Classifications - description: Credit management endpoints name: Credits - description: Datasets endpoints name: Datasets - description: Text embedding endpoints name: Embeddings - description: Endpoint information name: Endpoints - description: Files endpoints name: Files - description: Generation history endpoints name: Generations - description: Guardrails endpoints name: Guardrails - description: Images endpoints name: Images - description: Model information endpoints name: Models - description: OAuth authentication endpoints name: OAuth - description: Observability endpoints name: Observability - description: Organization endpoints name: Organization - description: Presets endpoints name: Presets - description: Provider information endpoints name: Providers - description: Rerank endpoints name: Rerank - description: Speech-to-text endpoints name: STT x-displayName: Transcriptions - description: Text-to-speech endpoints name: TTS x-displayName: Speech - description: Video Generation endpoints name: Video Generation - description: Workspaces endpoints name: Workspaces - description: beta.Analytics endpoints name: beta.Analytics - description: beta.responses endpoints name: beta.responses externalDocs: description: OpenRouter Documentation url: https://openrouter.ai/docs paths: /generation/content: get: tags: - Generations summary: Get stored prompt and completion content for a generation operationId: listGenerationContent parameters: - description: The generation ID in: query name: id required: true schema: description: The generation ID example: gen-1234567890 minLength: 1 type: string responses: '200': content: application/json: example: data: input: messages: - content: What is the meaning of life? role: user output: completion: The meaning of life is a philosophical question... reasoning: null schema: $ref: '#/components/schemas/GenerationContentResponse' description: Returns the stored prompt and completion content '401': content: application/json: example: error: code: 401 message: Missing Authentication header schema: $ref: '#/components/schemas/UnauthorizedResponse' description: Unauthorized - Authentication required or invalid credentials '403': content: application/json: example: error: code: 403 message: Only management keys can perform this operation schema: $ref: '#/components/schemas/ForbiddenResponse' description: Forbidden - Authentication successful but insufficient permissions '404': content: application/json: example: error: code: 404 message: Resource not found schema: $ref: '#/components/schemas/NotFoundResponse' description: Not Found - Resource does not exist '429': content: application/json: example: error: code: 429 message: Rate limit exceeded schema: ``` -------------------------------- ### Install Express and TypeScript Dependencies Source: https://openrouter.ai/docs/cookbook/video-generation/video-generation-webhooks Install the necessary Express and TypeScript development dependencies for adapting the provided Express examples in a local test project. ```bash npm install express npm install --save-dev @types/express tsx ``` -------------------------------- ### Initial Setup for MCP Client with OpenRouter Source: https://openrouter.ai/docs/cookbook/coding-agents/mcp-servers This snippet imports necessary libraries, loads environment variables, defines the LLM model, and configures the File System MCP server command for interaction. ```python import asyncio from typing import Optional from contextlib import AsyncExitStack from mcp import ClientSession, StdioServerParameters from mcp.client.stdio import stdio_client from openai import OpenAI from dotenv import load_dotenv import json load_dotenv() # load environment variables from .env MODEL = "anthropic/claude-3.7-sonnet" SERVER_CONFIG = { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", f"/Applications/"], "env": None } ``` -------------------------------- ### OpenAPI Specification for Get Guardrail by ID Source: https://openrouter.ai/docs/api/api-reference/guardrails/get-a-guardrail This OpenAPI YAML defines the `GET /guardrails/{id}` endpoint, including its parameters, expected responses (200, 401, 404), and example payloads. A management key is required for authentication. ```yaml openapi: 3.1.0 info: contact: email: support@openrouter.ai name: OpenRouter Support url: https://openrouter.ai/docs description: OpenAI-compatible API with additional OpenRouter features license: name: MIT url: https://opensource.org/licenses/MIT title: OpenRouter API version: 1.0.0 servers: - description: Production server url: https://openrouter.ai/api/v1 x-speakeasy-server-id: production security: - apiKey: [] tags: - description: API key management endpoints name: API Keys - description: Analytics and usage endpoints name: Analytics - description: Anthropic Messages endpoints name: Anthropic Messages - description: BYOK endpoints name: BYOK - description: Benchmarks endpoints name: Benchmarks - description: Chat completion endpoints name: Chat - description: Task classification market-share endpoints name: Classifications - description: Credit management endpoints name: Credits - description: Datasets endpoints name: Datasets - description: Text embedding endpoints name: Embeddings - description: Endpoint information name: Endpoints - description: Files endpoints name: Files - description: Generation history endpoints name: Generations - description: Guardrails endpoints name: Guardrails - description: Images endpoints name: Images - description: Model information endpoints name: Models - description: OAuth authentication endpoints name: OAuth - description: Observability endpoints name: Observability - description: Organization endpoints name: Organization - description: Presets endpoints name: Presets - description: Provider information endpoints name: Providers - description: Rerank endpoints name: Rerank - description: Speech-to-text endpoints name: STT x-displayName: Transcriptions - description: Text-to-speech endpoints name: TTS x-displayName: Speech - description: Video Generation endpoints name: Video Generation - description: Workspaces endpoints name: Workspaces - description: beta.Analytics endpoints name: beta.Analytics - description: beta.responses endpoints name: beta.responses externalDocs: description: OpenRouter Documentation url: https://openrouter.ai/docs paths: /guardrails/{id}: get: tags: - Guardrails summary: Get a guardrail description: >- Get a single guardrail by ID. [Management key](/docs/guides/overview/auth/management-api-keys) required. operationId: getGuardrail parameters: - description: The unique identifier of the guardrail to retrieve in: path name: id required: true schema: description: The unique identifier of the guardrail to retrieve example: 550e8400-e29b-41d4-a716-446655440000 format: uuid type: string responses: '200': content: application/json: example: data: allowed_models: null allowed_providers: - openai - anthropic - google created_at: '2025-08-24T10:30:00Z' description: Guardrail for production environment enforce_zdr: false id: 550e8400-e29b-41d4-a716-446655440000 ignored_models: null ignored_providers: null limit_usd: 100 name: Production Guardrail reset_interval: monthly updated_at: '2025-08-24T15:45:00Z' workspace_id: 0df9e665-d932-5740-b2c7-b52af166bc11 schema: $ref: '#/components/schemas/GetGuardrailResponse' description: Guardrail details '401': content: application/json: example: error: code: 401 message: Missing Authentication header schema: $ref: '#/components/schemas/UnauthorizedResponse' description: Unauthorized - Authentication required or invalid credentials '404': content: application/json: example: error: code: 404 message: Resource not found schema: $ref: '#/components/schemas/NotFoundResponse' description: Not Found - Resource does not exist ``` -------------------------------- ### FusionPlugin Full Example Configuration Source: https://openrouter.ai/docs/api/api-reference/anthropic-messages/create-a-message Illustrates a complete example configuration for the FusionPlugin, including analysis models, enabled status, ID, and the primary model. ```yaml analysis_models: - ~anthropic/claude-opus-latest - ~openai/gpt-latest - ~google/gemini-pro-latest enabled: true id: fusion model: ~anthropic/claude-opus-latest ``` -------------------------------- ### OpenAPI Specification for Get API Key by Hash Source: https://openrouter.ai/docs/api/api-reference/api-keys/get-a-single-api-key This OpenAPI YAML defines the `GET /keys/{hash}` endpoint, outlining its parameters, security requirements, and an example response for retrieving a single API key's details. ```yaml openapi: 3.1.0 info: contact: email: support@openrouter.ai name: OpenRouter Support url: https://openrouter.ai/docs description: OpenAI-compatible API with additional OpenRouter features license: name: MIT url: https://opensource.org/licenses/MIT title: OpenRouter API version: 1.0.0 servers: - description: Production server url: https://openrouter.ai/api/v1 x-speakeasy-server-id: production security: - apiKey: [] tags: - description: API key management endpoints name: API Keys - description: Analytics and usage endpoints name: Analytics - description: Anthropic Messages endpoints name: Anthropic Messages - description: BYOK endpoints name: BYOK - description: Benchmarks endpoints name: Benchmarks - description: Chat completion endpoints name: Chat - description: Task classification market-share endpoints name: Classifications - description: Credit management endpoints name: Credits - description: Datasets endpoints name: Datasets - description: Text embedding endpoints name: Embeddings - description: Endpoint information name: Endpoints - description: Files endpoints name: Files - description: Generation history endpoints name: Generations - description: Guardrails endpoints name: Guardrails - description: Images endpoints name: Images - description: Model information name: Models - description: OAuth authentication endpoints name: OAuth - description: Observability endpoints name: Observability - description: Organization endpoints name: Organization - description: Presets endpoints name: Presets - description: Provider information endpoints name: Providers - description: Rerank endpoints name: Rerank - description: Speech-to-text endpoints name: STT x-displayName: Transcriptions - description: Text-to-speech endpoints name: TTS x-displayName: Speech - description: Video Generation endpoints name: Video Generation - description: Workspaces endpoints name: Workspaces - description: beta.Analytics endpoints name: beta.Analytics - description: beta.responses endpoints name: beta.responses externalDocs: description: OpenRouter Documentation url: https://openrouter.ai/docs paths: /keys/{hash}: get: tags: - API Keys summary: Get a single API key description: >- Get a single API key by hash. [Management key](/docs/guides/overview/auth/management-api-keys) required. operationId: getKey parameters: - description: The hash identifier of the API key to retrieve in: path name: hash required: true schema: description: The hash identifier of the API key to retrieve example: f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943 type: string responses: '200': content: application/json: example: data: byok_usage: 17.38 byok_usage_daily: 17.38 byok_usage_monthly: 17.38 byok_usage_weekly: 17.38 created_at: '2025-08-24T10:30:00Z' creator_user_id: user_2dHFtVWx2n56w6HkM0000000000 disabled: false expires_at: '2027-12-31T23:59:59Z' hash: >- f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943 include_byok_in_limit: false label: Production API Key limit: 100 limit_remaining: 74.5 limit_reset: monthly name: My Production Key updated_at: '2025-08-24T15:45:00Z' usage: 25.5 usage_daily: 25.5 usage_monthly: 25.5 usage_weekly: 25.5 workspace_id: 0df9e665-d932-5740-b2c7-b52af166bc11 schema: example: data: byok_usage: 17.38 byok_usage_daily: 17.38 byok_usage_monthly: 17.38 byok_usage_weekly: 17.38 created_at: '2025-08-24T10:30:00Z' creator_user_id: user_2dHFtVWx2n56w6HkM0000000000 disabled: false expires_at: '2027-12-31T23:59:59Z' hash: >- ``` -------------------------------- ### OpenAPI Specification for Get Workspace Source: https://openrouter.ai/docs/api/api-reference/workspaces/get-a-workspace This OpenAPI 3.1.0 specification defines the `GET /workspaces/{id}` endpoint, including parameters, expected responses (200, 401, 404), and example payloads for retrieving a single workspace by its ID or slug. ```yaml openapi: 3.1.0 info: contact: email: support@openrouter.ai name: OpenRouter Support url: https://openrouter.ai/docs description: OpenAI-compatible API with additional OpenRouter features license: name: MIT url: https://opensource.org/licenses/MIT title: OpenRouter API version: 1.0.0 servers: - description: Production server url: https://openrouter.ai/api/v1 x-speakeasy-server-id: production security: - apiKey: [] tags: - description: API key management endpoints name: API Keys - description: Analytics and usage endpoints name: Analytics - description: Anthropic Messages endpoints name: Anthropic Messages - description: BYOK endpoints name: BYOK - description: Benchmarks endpoints name: Benchmarks - description: Chat completion endpoints name: Chat - description: Task classification market-share endpoints name: Classifications - description: Credit management endpoints name: Credits - description: Datasets endpoints name: Datasets - description: Text embedding endpoints name: Embeddings - description: Endpoint information name: Endpoints - description: Files endpoints name: Files - description: Generation history endpoints name: Generations - description: Guardrails endpoints name: Guardrails - description: Images endpoints name: Images - description: Model information endpoints name: Models - description: OAuth authentication endpoints name: OAuth - description: Observability endpoints name: Observability - description: Organization endpoints name: Organization - description: Presets endpoints name: Presets - description: Provider information endpoints name: Providers - description: Rerank endpoints name: Rerank - description: Speech-to-text endpoints name: STT x-displayName: Transcriptions - description: Text-to-speech endpoints name: TTS x-displayName: Speech - description: Video Generation endpoints name: Video Generation - description: Workspaces endpoints name: Workspaces - description: beta.Analytics endpoints name: beta.Analytics - description: beta.responses endpoints name: beta.responses externalDocs: description: OpenRouter Documentation url: https://openrouter.ai/docs paths: /workspaces/{id}: get: tags: - Workspaces summary: Get a workspace description: >- Get a single workspace by ID or slug. [Management key](/docs/guides/overview/auth/management-api-keys) required. operationId: getWorkspace parameters: - description: The workspace ID (UUID) or slug in: path name: id required: true schema: description: The workspace ID (UUID) or slug example: production minLength: 1 type: string responses: '200': content: application/json: example: data: created_at: '2025-08-24T10:30:00Z' created_by: user_abc123 default_image_model: openai/dall-e-3 default_provider_sort: price default_text_model: openai/gpt-4o description: Production environment workspace id: 550e8400-e29b-41d4-a716-446655440000 io_logging_api_key_ids: null io_logging_sampling_rate: 1 is_data_discount_logging_enabled: true is_observability_broadcast_enabled: false is_observability_io_logging_enabled: false name: Production slug: production updated_at: '2025-08-24T15:45:00Z' schema: $ref: '#/components/schemas/GetWorkspaceResponse' description: Workspace details '401': content: application/json: example: error: code: 401 message: Missing Authentication header schema: $ref: '#/components/schemas/UnauthorizedResponse' description: Unauthorized - Authentication required or invalid credentials '404': content: application/json: example: error: code: 404 message: Resource not found schema: $ref: '#/components/schemas/NotFoundResponse' description: Not Found - The specified resource was not found ``` -------------------------------- ### OpenAPI Specification for Get Generation Metadata Source: https://openrouter.ai/docs/api/api-reference/generations/get-request-%26-usage-metadata-for-a-generation This OpenAPI YAML defines the `GET /generation` endpoint, allowing retrieval of request and usage metadata for a specific AI generation by its ID. It includes details on parameters, responses, and example data. ```yaml openapi: 3.1.0 info: contact: email: support@openrouter.ai name: OpenRouter Support url: https://openrouter.ai/docs description: OpenAI-compatible API with additional OpenRouter features license: name: MIT url: https://opensource.org/licenses/MIT title: OpenRouter API version: 1.0.0 servers: - description: Production server url: https://openrouter.ai/api/v1 x-speakeasy-server-id: production security: - apiKey: [] tags: - description: API key management endpoints name: API Keys - description: Analytics and usage endpoints name: Analytics - description: Anthropic Messages endpoints name: Anthropic Messages - description: BYOK endpoints name: BYOK - description: Benchmarks endpoints name: Benchmarks - description: Chat completion endpoints name: Chat - description: Task classification market-share endpoints name: Classifications - description: Credit management endpoints name: Credits - description: Datasets endpoints name: Datasets - description: Text embedding endpoints name: Embeddings - description: Endpoint information name: Endpoints - description: Files endpoints name: Files - description: Generation history endpoints name: Generations - description: Guardrails endpoints name: Guardrails - description: Images endpoints name: Images - description: Model information endpoints name: Models - description: OAuth authentication endpoints name: OAuth - description: Observability endpoints name: Observability - description: Organization endpoints name: Organization - description: Presets endpoints name: Presets - description: Provider information endpoints name: Providers - description: Rerank endpoints name: Rerank - description: Speech-to-text endpoints name: STT x-displayName: Transcriptions - description: Text-to-speech endpoints name: TTS x-displayName: Speech - description: Video Generation endpoints name: Video Generation - description: Workspaces endpoints name: Workspaces - description: beta.Analytics endpoints name: beta.Analytics - description: beta.responses endpoints name: beta.responses externalDocs: description: OpenRouter Documentation url: https://openrouter.ai/docs paths: /generation: get: tags: - Generations summary: Get request & usage metadata for a generation operationId: getGeneration parameters: - description: The generation ID in: query name: id required: true schema: description: The generation ID example: gen-1234567890 minLength: 1 type: string responses: '200': content: application/json: example: data: api_type: completions app_id: 12345 cache_discount: null cancelled: false created_at: '2024-07-15T23:33:19.433273+00:00' external_user: user-123 finish_reason: stop generation_time: 1200 http_referer: https://openrouter.ai/ id: gen-3bhGkxlo4XFrqiabUM7NDtwDzWwG is_byok: false latency: 1250 model: sao10k/l3-stheno-8b moderation_latency: 50 native_finish_reason: stop native_tokens_cached: 3 native_tokens_completion: 25 native_tokens_completion_images: 0 native_tokens_prompt: 10 native_tokens_reasoning: 5 num_input_audio_prompt: 0 num_media_completion: 0 num_media_prompt: 1 num_search_results: 5 origin: https://openrouter.ai/ provider_name: Infermatic provider_responses: null request_id: req-1727282430-aBcDeFgHiJkLmNoPqRsT router: openrouter/auto session_id: null streamed: true tokens_completion: 25 tokens_prompt: 10 total_cost: 0.0015 upstream_id: chatcmpl-791bcf62-080e-4568-87d0-94c72e3b4946 upstream_inference_cost: 0.0012 usage: 0.0015 user_agent: Mozilla/5.0 schema: $ref: '#/components/schemas/GenerationResponse' description: Returns the request metadata for this generation ``` -------------------------------- ### FusionPlugin Tools Configuration Example Source: https://openrouter.ai/docs/api/api-reference/anthropic-messages/create-a-message Shows an example configuration for server tools available to FusionPlugin panelists and the judge, including web search and web fetch with parameters. ```yaml - parameters: excluded_domains: - example.com type: openrouter:web_search - type: openrouter:web_fetch ``` -------------------------------- ### Install OpenCode using various methods Source: https://openrouter.ai/docs/cookbook/coding-agents/opencode-integration Use one of these commands to install OpenCode via a direct script, npm, or Homebrew, depending on your preferred package manager. ```bash curl -fsSL https://opencode.ai/install | bash ``` ```bash npm install -g opencode-ai ``` ```bash brew install anomalyco/tap/opencode ``` -------------------------------- ### OpenAPI Specification for Get Remaining Credits Source: https://openrouter.ai/docs/api/api-reference/credits/get-remaining-credits This OpenAPI YAML defines the `/credits` GET endpoint, detailing its summary, description, required management key, and expected 200 and error responses, including example credit usage data. ```yaml openapi: 3.1.0 info: contact: email: support@openrouter.ai name: OpenRouter Support url: https://openrouter.ai/docs description: OpenAI-compatible API with additional OpenRouter features license: name: MIT url: https://opensource.org/licenses/MIT title: OpenRouter API version: 1.0.0 servers: - description: Production server url: https://openrouter.ai/api/v1 x-speakeasy-server-id: production security: - apiKey: [] tags: - description: API key management endpoints name: API Keys - description: Analytics and usage endpoints name: Analytics - description: Anthropic Messages endpoints name: Anthropic Messages - description: BYOK endpoints name: BYOK - description: Benchmarks endpoints name: Benchmarks - description: Chat completion endpoints name: Chat - description: Task classification market-share endpoints name: Classifications - description: Credit management endpoints name: Credits - description: Datasets endpoints name: Datasets - description: Text embedding endpoints name: Embeddings - description: Endpoint information name: Endpoints - description: Files endpoints name: Files - description: Generation history endpoints name: Generations - description: Guardrails endpoints name: Guardrails - description: Images endpoints name: Images - description: Model information endpoints name: Models - description: OAuth authentication endpoints name: OAuth - description: Observability endpoints name: Observability - description: Organization endpoints name: Organization - description: Presets endpoints name: Presets - description: Provider information endpoints name: Providers - description: Rerank endpoints name: Rerank - description: Speech-to-text endpoints name: STT x-displayName: Transcriptions - description: Text-to-speech endpoints name: TTS x-displayName: Speech - description: Video Generation endpoints name: Video Generation - description: Workspaces endpoints name: Workspaces - description: beta.Analytics endpoints name: beta.Analytics - description: beta.responses endpoints name: beta.responses externalDocs: description: OpenRouter Documentation url: https://openrouter.ai/docs paths: /credits: get: tags: - Credits summary: Get remaining credits description: >- Get total credits purchased and used for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required. operationId: getCredits responses: '200': content: application/json: example: data: total_credits: 100.5 total_usage: 25.75 schema: description: Total credits purchased and used example: data: total_credits: 100.5 total_usage: 25.75 properties: data: example: total_credits: 100.5 total_usage: 25.75 properties: total_credits: description: Total credits purchased example: 100.5 format: double type: number total_usage: description: Total credits used example: 25.75 format: double type: number required: - total_credits - total_usage type: object required: - data type: object description: Returns the total credits purchased and used '401': content: application/json: example: error: code: 401 message: Missing Authentication header schema: $ref: '#/components/schemas/UnauthorizedResponse' description: Unauthorized - Authentication required or invalid credentials '403': content: application/json: example: error: code: 403 message: Only management keys can perform this operation schema: ``` -------------------------------- ### Computer Use Server Tool Configuration Example (OpenAPI) Source: https://openrouter.ai/docs/api/api-reference/responses/create-a-response Example configuration for the Computer Use Server Tool, defining display dimensions and the operating environment. ```yaml display_height: 768 display_width: 1024 environment: linux type: computer_use_preview ``` -------------------------------- ### OpenAPI Specification for Get Current API Key Source: https://openrouter.ai/docs/api/api-reference/api-keys/get-current-api-key This YAML snippet defines the OpenAPI 3.1.0 specification for the `GET /key` endpoint, detailing its summary, description, operation ID, and an example JSON response for successful retrieval of API key information. ```yaml openapi: 3.1.0 info: contact: email: support@openrouter.ai name: OpenRouter Support url: https://openrouter.ai/docs description: OpenAI-compatible API with additional OpenRouter features license: name: MIT url: https://opensource.org/licenses/MIT title: OpenRouter API version: 1.0.0 servers: - description: Production server url: https://openrouter.ai/api/v1 x-speakeasy-server-id: production security: - apiKey: [] tags: - description: API key management endpoints name: API Keys - description: Analytics and usage endpoints name: Analytics - description: Anthropic Messages endpoints name: Anthropic Messages - description: BYOK endpoints name: BYOK - description: Benchmarks endpoints name: Benchmarks - description: Chat completion endpoints name: Chat - description: Task classification market-share endpoints name: Classifications - description: Credit management endpoints name: Credits - description: Datasets endpoints name: Datasets - description: Text embedding endpoints name: Embeddings - description: Endpoint information name: Endpoints - description: Files endpoints name: Files - description: Generation history endpoints name: Generations - description: Guardrails endpoints name: Guardrails - description: Images endpoints name: Images - description: Model information endpoints name: Models - description: OAuth authentication endpoints name: OAuth - description: Observability endpoints name: Observability - description: Organization endpoints name: Organization - description: Presets endpoints name: Presets - description: Provider information endpoints name: Providers - description: Rerank endpoints name: Rerank - description: Speech-to-text endpoints name: STT x-displayName: Transcriptions - description: Text-to-speech endpoints name: TTS x-displayName: Speech - description: Video Generation endpoints name: Video Generation - description: Workspaces endpoints name: Workspaces - description: beta.Analytics endpoints name: beta.Analytics - description: beta.responses endpoints name: beta.responses externalDocs: description: OpenRouter Documentation url: https://openrouter.ai/docs paths: /key: get: tags: - API Keys summary: Get current API key description: >- Get information on the API key associated with the current authentication session operationId: getCurrentKey responses: '200': content: application/json: example: data: byok_usage: 17.38 byok_usage_daily: 17.38 byok_usage_monthly: 17.38 byok_usage_weekly: 17.38 creator_user_id: user_2dHFtVWx2n56w6HkM0000000000 expires_at: '2027-12-31T23:59:59Z' include_byok_in_limit: false is_free_tier: false is_management_key: false is_provisioning_key: false label: sk-or-v1-au7...890 limit: 100 limit_remaining: 74.5 limit_reset: monthly rate_limit: interval: 1h note: This field is deprecated and safe to ignore. requests: 1000 usage: 25.5 usage_daily: 25.5 usage_monthly: 25.5 usage_weekly: 25.5 schema: example: data: byok_usage: 17.38 byok_usage_daily: 17.38 byok_usage_monthly: 17.38 byok_usage_weekly: 17.38 creator_user_id: user_2dHFtVWx2n56w6HkM0000000000 expires_at: '2027-12-31T23:59:59Z' include_byok_in_limit: false is_free_tier: false is_management_key: false is_provisioning_key: false label: sk-or-v1-au7...890 limit: 100 limit_remaining: 74.5 limit_reset: monthly rate_limit: interval: 1h note: This field is deprecated and safe to ignore. requests: 1000 usage: 25.5 usage_daily: 25.5 usage_monthly: 25.5 ``` -------------------------------- ### Web Fetch Server Tool Example (OpenAPI YAML) Source: https://openrouter.ai/docs/api/api-reference/presets/create-a-preset-from-a-responses-request-body Demonstrates the OpenAPI `example` structure for the Web Fetch server tool, including its `type` and typical `parameters`. ```yaml parameters: max_uses: 10 type: openrouter:web_fetch ``` -------------------------------- ### Web Search Server Tool Example (OpenAPI YAML) Source: https://openrouter.ai/docs/api/api-reference/presets/create-a-preset-from-a-responses-request-body Demonstrates the OpenAPI `example` structure for the Web Search server tool, including its `type` and typical `parameters`. ```yaml parameters: max_results: 5 type: openrouter:web_search ``` -------------------------------- ### Get Credits using Standalone Function Source: https://openrouter.ai/docs/agent-sdk/typescript/api-reference/credits This example shows how to use the `creditsGetCredits` standalone function with `OpenRouterCore` for better tree-shaking performance. It includes error handling for the response. ```typescript import { OpenRouterCore } from "@openrouter/sdk/core.js"; import { creditsGetCredits } from "@openrouter/sdk/funcs/creditsGetCredits.js"; // Use `OpenRouterCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const openRouter = new OpenRouterCore({ httpReferer: "", appTitle: "", appCategories: "", apiKey: process.env["OPENROUTER_API_KEY"] ?? "", }); async function run() { const res = await creditsGetCredits(openRouter); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("creditsGetCredits failed:", res.error); } } run(); ``` -------------------------------- ### Files Server Tool Example (OpenAPI YAML) Source: https://openrouter.ai/docs/api/api-reference/presets/create-a-preset-from-a-responses-request-body Demonstrates the OpenAPI `example` structure for the Files server tool, including its `type` and typical `parameters`. ```yaml parameters: {} type: openrouter:files ``` -------------------------------- ### Create Skill Directories Source: https://openrouter.ai/docs/agent-sdk/call-model/examples/skills-loader Sets up the directory structure for storing different specialized skills. ```bash mkdir -p ~/.claude/skills/pdf-processing mkdir -p ~/.claude/skills/data-analysis mkdir -p ~/.claude/skills/code-review ``` -------------------------------- ### Actionable Error Messages in OpenRouter TypeScript SDK Source: https://openrouter.ai/docs/agent-sdk/typescript/overview Shows an example of a specific, helpful error message provided by the SDK, guiding users on how to correct invalid API requests. ```typescript // Instead of generic errors, get specific guidance: // "Model 'openai/o1-preview' requires at least 2 messages. // You provided 1 message. Add a system or user message." ``` -------------------------------- ### Quick Start: Sending Requests to Fusion Router Source: https://openrouter.ai/docs/guides/routing/routers/fusion-router These examples illustrate how to send chat completion requests to the "openrouter/fusion" model using the TypeScript SDK and a cURL command. ```typescript import { OpenRouter } from '@openrouter/sdk'; const openRouter = new OpenRouter({ apiKey: '', }); const completion = await openRouter.chat.send({ model: 'openrouter/fusion', messages: [ { role: 'user', content: 'Survey the strongest arguments for and against a carbon tax. Where do experts disagree?', }, ], }); console.log(completion.choices[0].message.content); ``` ```bash curl https://openrouter.ai/api/v1/chat/completions \ -H "Authorization: Bearer $OPENROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "openrouter/fusion", "messages": [ {"role": "user", "content": "Survey the strongest arguments for and against a carbon tax. Where do experts disagree?"} ] }' ``` -------------------------------- ### Install OpenRouter Client SDK Source: https://openrouter.ai/docs/quickstart Install the OpenRouter Client SDK using your preferred package manager. ```bash npm install @openrouter/sdk ``` ```bash yarn add @openrouter/sdk ``` ```bash pnpm add @openrouter/sdk ``` ```bash pip install openrouter ```