") return input; return decide("HTML", input, json(input)); }, createScript: function (input) { return decide("script", input, json(input)); }, createScriptURL: function (input) { var safe = null; try { var url = new URL(input, document.baseURI); if (url.origin === location.origin || SCRIPT_URL_ORIGINS.indexOf(url.origin) !== -1) safe = url.href; } catch (e) {} return decide("script URL", input, safe); }, }); } catch (e) {} })();
OpenRouter logo

API Integration

OpenRouter API for AI Agents

OpenRouter provides a unified, OpenAI-compatible routing gateway to over 400+ AI models across major providers (OpenAI, Anthropic, Google, Meta, Mistral, DeepSeek, etc.). Beyond chat completions (/chat/completions) with tool calling, multi-modal input, reasoning controls, and automated provider fallback, the API covers embeddings, audio, batch inference (/batches), model discovery (/models), API key management (/auth/keys), activity logs, and credit tracking (/credits). Call the OpenRouter API from the agent stack you already run. Swytchcode supplies the manifest, then handles authentication, retries, idempotency, and validation on every call.

Copy paste to your AI agent

Provider
OpenRouter
Category
General
License
Proprietary
Manifest
openrouter
Official site
openrouter.ai
API docs
View docs

Use cases

What can you build with the OpenRouter API?

Copy a prompt for the kind of OpenRouter assistant you want. Each one includes the skills.md setup.

Catch-up assistant

Lookup assistant

Failure watcher

Status writer

Record assistant

Access advisor

Setup guide

How to connect the OpenRouter API to an AI agent

Four steps, no SDK, no boilerplate. Every OpenRouter call routed through Swytchcode is idempotency-keyed and safe to retry.

  1. 1

    Install the CLI

    Run "npx swytchcode" to install the Swytchcode CLI—no account required to start.

  2. 2

    Pull the manifest

    Run "swytchcode get openrouter" to pull the OpenRouter API manifest, including its schema and available actions.

  3. 3

    Authenticate once

    Provide your OpenRouter API credentials a single time. Swytchcode stores and refreshes them so your agent never handles raw secrets.

  4. 4

    Call it from your agent

    Run "swytchcode exec openrouter.<action> --key value" from any agent or script. No SDK, no framework lock-in.

swytchcode get openrouter
swytchcode exec openrouter.<action> --key value

FAQ

Frequently asked questions

Build me an OpenRouter AI assistant

Copy the prompt into your agent. It will load Swytchcode and wire up OpenRouter.