Thank you for your interest in contributing to the OpenRouter provider for the Vercel AI SDK! This guide will help you get started as a contributor.
- Node.js v18 or higher
- pnpm v9.15.0 or higher (the project uses pnpm as its package manager)
-
Fork the repository on GitHub
-
Clone your fork locally:
git clone https://github.com/YOUR-USERNAME/ai-sdk-provider.git cd ai-sdk-provider -
Install dependencies:
pnpm install
-
Build the project:
pnpm build
To build the package during development:
# Build once
pnpm build
# Build in watch mode for continuous development
pnpm devWe use Biome for code linting and formatting. Before submitting a PR, make sure your code passes all checks:
# Check both linting and formatting
pnpm stylecheck
# Fix formatting issues automatically
pnpm format
# Run linting and formatting checks
pnpm stylecheckEnsure your changes pass TypeScript type checking:
pnpm typecheckThe project includes tests for both Node.js and Edge environments. Make sure to run the tests before submitting a PR:
# Run all tests
pnpm test
# Run only Node.js tests
pnpm test:node
# Run only Edge environment tests
pnpm test:edgeWhen adding new features or fixing bugs, please include tests. Test files follow the naming convention of *.test.ts and are located in the same directory as the files they test.
Examples of test files include:
openrouter-chat-language-model.test.tsopenrouter-usage-accounting.test.tsopenrouter-stream-usage-accounting.test.ts
When fixing bugs reported in GitHub issues, add a regression test to the e2e/issues/ directory. This ensures the issue doesn't recur and provides traceability back to the original report.
Running issue regression tests:
# Run issue regression tests separately (not included in test:e2e)
pnpm test:issuesNote: Issue regression tests are excluded from
pnpm test:e2ebecause they may hit different models/APIs that could be slow or rate-limited. Run them separately when needed.
File naming convention: issue-{number}-{brief-description}.test.ts
Required test file structure:
/**
* Regression test for GitHub issue #{number}
* https://github.com/OpenRouterTeam/ai-sdk-provider/issues/{number}
*
* Reported error: {exact error message from the issue}
* Model: {model ID if applicable}
*
* This test verifies that {what the test checks}.
*/
import { ... } from 'ai';
import { describe, expect, it, vi } from 'vitest';
import { createOpenRouter } from '@/src';
describe('Issue #{number}: {brief description}', () => {
// Test cases that verify the issue is resolved
});Note: Only include known facts from the issue report (error message, model, SDK version). Do not include speculative root cause analysis.
When to add issue regression tests:
- Bug fixes that have a clear reproduction case
- Issues that could potentially regress
- API compatibility issues with specific models or features
When NOT to add issue regression tests:
- Documentation-only changes
- Issues that were user configuration errors
- Transient API issues that were fixed server-side (though you may still add one for monitoring)
When adding new features to the OpenRouter provider:
- Start by understanding the existing architecture in the
srcdirectory - Update the relevant type definitions in
types.tsif needed - Implement the feature in the appropriate files
- Add tests to verify the functionality
- Update the README.md to document the new feature
- Update the CHANGELOG.md if applicable
The usage accounting feature provides an example of how to add features to the provider:
- Added types in
types.tsfor usage accounting - Enhanced response schemas to include usage data
- Updated the implementation in
openrouter-chat-language-model.ts - Added tests in
openrouter-usage-accounting.test.tsandopenrouter-stream-usage-accounting.test.ts - Updated README.md with usage examples
Important: All PRs that should trigger a release must include a changeset. Run
pnpm changesetbefore submitting your PR.
-
Create a new branch for your changes
-
Make your changes, including tests and documentation updates
-
Add a changeset to describe your changes:
pnpm changeset
This will prompt you to select the type of change (patch/minor/major) and write a summary. The changeset will be used to automatically generate release notes and bump versions.
- patch: Bug fixes and small changes that don't affect the API
- minor: New features that are backwards-compatible
- major: Breaking changes
If your changes don't need a release (docs, tests, CI config), create an empty changeset:
pnpm changeset --empty
-
Run all checks locally before submitting:
pnpm stylecheck # Check formatting pnpm typecheck # Check types pnpm build # Build the project pnpm test # Run all tests
-
Fix any issues found by the checks (use
pnpm formatfor formatting) -
Commit with clear, descriptive messages (including the changeset file)
-
Push to your fork and submit a pull request
-
Update the PR description with any relevant information
Note: Our CI will automatically run all these checks on your PR. PRs with failing checks cannot be merged.
Use a descriptive title that explains the change:
fix: <description>for bug fixesfeat: <description>for new featuresdocs: <description>for documentation changestest: <description>for test changeschore: <description>for maintenance tasks
This project uses Changesets for automated release management.
-
Contributors add changesets: When you submit a PR with changes that affect the public API or fix bugs, you include a changeset file (created with
pnpm changeset) that describes your changes. -
Automated version PR: When PRs with changesets are merged to
main, the Release workflow automatically creates or updates a "Version Packages" PR. This PR:- Bumps the version in
package.jsonbased on all pending changesets - Updates
CHANGELOG.mdwith all changes since the last release - Removes the changeset files that have been processed
- Bumps the version in
-
Publish to npm: When a maintainer merges the "Version Packages" PR, the package is automatically published to npm with provenance.
To release a new version:
- Review the automatically created "Version Packages" PR
- Verify the version bump is appropriate
- Verify the CHANGELOG entries are accurate
- Merge the PR
- The Release workflow will automatically publish to npm
In case of emergency, a manual release can be triggered using the legacy publish-manual.yaml workflow by creating a GitHub Release. This should only be used when the automated process is unavailable.
If you have questions about contributing, please open a GitHub issue in the repository.
Thank you for contributing to the OpenRouter AI SDK Provider!