This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
OpenRouter Provider for Vercel AI SDK (@openrouter/ai-sdk-provider) - A TypeScript provider that integrates OpenRouter's API with the Vercel AI SDK, enabling access to 300+ language models through a unified interface.
pnpm build # Build with tsup (ESM + CJS outputs)
pnpm dev # Watch mode development build
pnpm test # Run all tests (node + edge environments)
pnpm test:node # Run Node.js tests only
pnpm test:edge # Run Edge runtime tests only
pnpm test:e2e # Run E2E tests (requires OPENROUTER_API_KEY in .env.e2e)
pnpm typecheck # TypeScript type checking
pnpm stylecheck # Biome linting + formatting check
pnpm format # Auto-fix formatting issues
pnpm changeset # Create a changeset for releasepnpm vitest run src/chat/index.test.ts # Single test file (node)
pnpm vitest run src/chat/index.test.ts -t "test name" # Specific test by namesrc/
├── provider.ts # Factory: createOpenRouter() and default openrouter instance
├── facade.ts # Deprecated OpenRouter class (legacy support)
├── chat/index.ts # OpenRouterChatLanguageModel - main chat implementation
├── completion/index.ts # OpenRouterCompletionLanguageModel - completions
├── embedding/index.ts # OpenRouterEmbeddingModel - embeddings
├── evaluation/index.ts # OpenRouterEvaluationModel - Decisions API (/api/alpha) for experimental_evaluate
├── types/ # TypeScript interfaces for settings
├── schemas/ # Zod schemas for request/response validation
└── internal/ # Conditional export: @openrouter/ai-sdk-provider/internal
- Provider Factory:
createOpenRouter(options)returns a provider with.chat(),.completion(),.textEmbeddingModel(), and.decisionModel()(alias.evaluationModel()) methods - Message Conversion:
convert-to-openrouter-chat-messages.tstransforms AI SDK messages to OpenRouter format (handles images, files, cache control, tool results) - Dual Build Output: tsup generates both main (
dist/) and internal (dist/internal/) exports
Tests run in three environments via separate Vitest configs:
- Node.js (
vitest.node.config.ts) - Server-side tests - Edge Runtime (
vitest.edge.config.ts) - Serverless compatibility - E2E (
vitest.e2e.config.ts) - Real API integration (uses.env.e2e)
Test files are co-located with source: src/chat/index.test.ts tests src/chat/index.ts.
- Biome for linting/formatting (2 spaces, single quotes, 80 char line width)
- Tests may use explicit any and console (configured in biome.json overrides)
- Import organization: type imports first, then regular imports, then aliases
After completing any implementation task, automatically:
- Commit all changes (including
package.json,pnpm-lock.yaml) - Run
pnpm stylecheck && pnpm typecheck && pnpm test && pnpm build - Add changeset (
pnpm changeset --emptyfor non-user-facing changes) - Create PR on a
claude/branch using the template in.github/PULL_REQUEST_TEMPLATE.md - Wait for CI to pass, fix any issues
- Provide the PR link when complete
Key principle: Always ensure git state is clean and CI passes before considering work complete. Local tests can pass with uncommitted dependency changes - CI is the source of truth.