OpenRouter AI SDK Provider

The official OpenRouter provider for the Vercel AI SDK, unlocking 300+ LLMs through one unified TypeScript client.

SDK
npm
v3.1.0
690 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
83 /100 Excellent
Development Activity 84
Maintenance 88
Community 72
Maturity 48
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
86 /100 Excellent
Architecture 86
Code Quality 85
Innovation 88
Learning Curve 82

OpenRouter AI SDK Provider is the official adapter that plugs OpenRouter into the Vercel AI SDK, giving your application a single, type-safe entry point to more than 300 large language models from OpenAI, Anthropic, Google, Meta, and dozens of other providers. Instead of wiring up a separate SDK for each vendor, you import one openrouter instance and pass a model id like openai/gpt-4o or anthropic/claude-sonnet-4 to the AI SDK’s generateText, streamText, generateObject, and embed functions.

Because it implements the AI SDK provider interface, it drops into any existing AI SDK codebase without new call patterns, while exposing OpenRouter-specific capabilities such as usage accounting, prompt caching, provider routing, response healing, and per-request extra body. It is ESM-only, ships full TypeScript types, and tracks the AI SDK v7 release line.

What You Get

  • A drop-in Vercel AI SDK provider that exposes 300+ models through one import
  • Full TypeScript type definitions and ESM-only, tree-shakeable output
  • Chat, completion, embedding, image, and video model factories under one client
  • OpenRouter-native features: usage accounting, prompt caching, provider routing, and response healing
  • Per-request and per-model extra body plus custom header passthrough for provider-specific options

Common Use Cases

  • Switching between LLM vendors without rewriting application code
  • Building streaming chat and agentic tool-use features on top of the AI SDK
  • Generating structured JSON output with schema validation and response healing
  • Powering RAG and semantic search with OpenRouter embedding models

Under The Hood

Architecture — The package is organized by modality: src/facade.ts exposes a deprecated OpenRouter class while src/provider.ts builds the modern createOpenRouter factory that returns a callable OpenRouterProvider (invoking it directly returns a chat model). Each modality lives in its own directory (chat, completion, embedding, image, video), and every factory constructs a language-model class (e.g. OpenRouterChatLanguageModel) with a shared base config that lazily assembles auth and app-identity headers via loadApiKey, injecting X-OpenRouter-Title, HTTP-Referer, and optional X-Provider-API-Keys. src/index.ts re-exports the facade, provider, and types.

Tech Stack — Written in TypeScript (99% of the codebase), it declares peer dependencies on ai@^7.0.0 and zod, and builds against @ai-sdk/provider and @ai-sdk/provider-utils. It is bundled with tsup, linted and formatted with Biome, tested with Vitest across node, edge, e2e, and issues configs, and released via Changesets with npm provenance. Output is ESM-only, side-effect-free, and requires Node.js 22+.

Code Quality — The repo carries roughly 21 in-tree unit tests plus around 56 end-to-end tests, exercising node and edge runtimes with MSW-based request mocking. Public options are documented with JSDoc, types are strict, and deprecated surfaces (the OpenRouter class, embedding()) are clearly annotated with forward pointers to their replacements.

API Design — The developer experience is deliberately minimal: import { openrouter } and call openrouter('openai/gpt-4o'), or createOpenRouter({ apiKey }) for configuration. Model ids are typed, provider-specific behavior flows through providerOptions.openrouter, extraBody, and headers at either the factory or request level, and because it conforms to the AI SDK provider contract, existing generateText/streamText/generateObject/embed code works with zero new call patterns.

Used by 25 apps in this directory

TypeScript
94%
MIT

open-seo

Developer Tools · Marketing

24,707

Pay-as-you-go open source SEO platform with MCP integration — keyword research, rank tracking, backlinks, site audits, and AI brand visibility in one self-hosted tool.

View details
83
Repo Health
79
Technical
74
Dependency
Built with
TypeScript 94%
Updated 6 days ago
TypeScript
81%
MIT

OpenCode

AI Code Assistants

220,711

A fully open-source AI coding agent built for the terminal, with a TUI, desktop app, web client, plugin system, and SDK — one of the most-starred AI coding agents on GitHub.

View details
89
Repo Health
76
Technical
66
Dependency
Built with
TypeScript 81%
MDX 16%
Updated 5 days ago
TypeScript
98%
Apache 2.0

rowboat

AI Assistants · AI Development

18,060

Build, test, and deploy multi-agent AI workflows with a visual editor, RAG data sources, MCP tool integration, and a production-ready REST API.

View details
88
Repo Health
72
Technical
65
Dependency
Built with
TypeScript 98%
Updated 6 days ago
Python
100%
Other

Sourcebot

AI Code Assistants · Developer Tools · Search

4,005

A self-hosted, AI-powered code search engine that indexes every repo across GitHub, GitLab, Bitbucket, Gitea, Gerrit, and Azure DevOps, so both engineers and coding agents can search, browse, and ask questions about your codebase from one place.

View details
86
Repo Health
83
Technical
61
Dependency
Built with
Python 100%
Updated 1 weeks ago
TypeScript
89%
Other

Hexclave

Authentication · Developer Tools

6,877

The open-source user infrastructure platform — authentication, teams, payments, emails, analytics, and more on a single unified user model.

View details
88
Repo Health
80
Technical
66
Dependency
Built with
TypeScript 89%
Updated 5 days ago
TypeScript
99%
Other

Teable

Databases · No Code Platforms

21,920

A no-code PostgreSQL database with spreadsheet UX, real-time collaboration, and native AI agents — built for teams that outgrow Airtable.

View details
78
Repo Health
76
Technical
62
Dependency
Built with
TypeScript 99%
Updated 6 days ago
TypeScript
65%
Other

Typebot

AI Assistants · AI Development · Developer Tools

10,576

Build sophisticated chatbots visually, embed them anywhere without iframes, and own your data — fully self-hostable with a modular block system and 30+ integrations.

View details
94
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 65%
MDX 34%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers