-
Notifications
You must be signed in to change notification settings - Fork 281
feat(openrouter): add OpenRouter plugin with 13 operations #635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Mayank-saraswal
wants to merge
8
commits into
corsairdev:main
Choose a base branch
from
Mayank-saraswal:feat/openrouter-plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
974c387
feat(openrouter): add OpenRouter plugin with 14 endpoints
Mayank-saraswal 6109890
fix(openrouter): document and tighten public zod schemas
Mayank-saraswal ad11fbc
fix(openrouter): align supported API contracts
ambikeesshh 9bf4208
fix(openrouter): correct docs and provider name
ambikeesshh 515b868
chore(openrouter): clean lockfile scope
ambikeesshh e2394d0
fix(openrouter): address latest review findings
ambikeesshh ccbc202
fix(openrouter): require integer chat token limits
ambikeesshh f011727
fix(openrouter): cache models, providers, and generations
ambikeesshh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| # @corsair-dev/openrouter | ||
|
|
||
| Corsair plugin for the [OpenRouter API](https://openrouter.ai/docs). | ||
|
|
||
| ## Auth setup | ||
|
|
||
| API-key only. | ||
|
|
||
| 1. Create a key at [openrouter.ai/keys](https://openrouter.ai/keys) | ||
| 2. Store it in Corsair credentials, or pass it explicitly with `openrouter({ key })` | ||
|
|
||
| Credentials are sent as `Authorization: Bearer <key>`. | ||
|
|
||
| Missing credentials throw `AuthMissingError` (never an empty string). | ||
| An explicit `options.key` overrides tenant-managed credentials for every tenant. | ||
| Setting `OPENROUTER_API_KEY` alone is only used by this package's optional live | ||
| tests; application code must pass it through `options.key` or Corsair credentials. | ||
|
|
||
| ## Endpoint overview | ||
|
|
||
| | Operation | OpenRouter path | Description | | ||
| | ------------------------ | --------------------------------------- | -------------------------------------------------------------------------------------------- | | ||
| | `chatCompletions.create` | `POST /chat/completions` | Chat completions with multi-provider routing, fallbacks, tool calling, and structured output | | ||
| | `messages.create` | `POST /messages` | Anthropic Messages API with image, document, tool-use, and thinking blocks | | ||
| | `models.list` | `GET /models` | List all models with pricing, context length, and supported parameters | | ||
| | `models.count` | `GET /models/count` | Total count of models available on OpenRouter | | ||
| | `models.listEmbeddings` | `GET /embeddings/models` | List all embedding models | | ||
| | `models.listUser` | `GET /models/user` | List models filtered by the user's provider preferences, privacy settings, and guardrails | | ||
| | `embeddings.create` | `POST /embeddings` | Generate vector embeddings | | ||
| | `modelEndpoints.list` | `GET /models/{author}/{slug}/endpoints` | Per-provider endpoints for a model (pricing, latency, throughput) | | ||
| | `providers.list` | `GET /providers` | List providers with privacy policies and data-center regions | | ||
| | `zdr.list` | `GET /endpoints/zdr` | Zero-Data Residency (ZDR) endpoint specification for the account | | ||
| | `generations.get` | `GET /generation?id={id}` | Request & usage metadata for a previous generation | | ||
| | `credits.list` | `GET /credits` | Credit balance and usage (management API key required) | | ||
| | `key.get` | `GET /key` | API key metadata (usage, limits, rate limits) | | ||
|
|
||
| No webhooks (OpenRouter's API surface is token-only; there are no signed | ||
| inbound events to subscribe to). | ||
|
|
||
| ## Quirks & caveats | ||
|
|
||
| - **Streaming is not exposed.** Completion and message calls always send | ||
| `stream: false` so responses are a single JSON body, not SSE events. | ||
| - **Routing happens automatically.** OpenRouter picks the provider unless you | ||
| pass `provider.order` / `provider.ignore` or pin `models` / `route`. | ||
| - **Model availability varies by key.** Free-tier keys only reach a subset of | ||
| providers; `models.list` returns what the key can access. | ||
| - **Chat calls cost credits.** Listing models/providers/credits/key works even | ||
| at `$0` balance; chat, message, and embedding calls return HTTP 402 if the | ||
| account has insufficient credits. | ||
| - **Transient 5xx and timeout errors are retried only for read operations.** | ||
| Paid chat, message, and embedding writes are not retried because repeating a | ||
| completed request can double-charge the account. | ||
| - **Balances are `data`-wrapped.** `/credits` and `/key` return their payload | ||
| under a `data` key (e.g. `{ data: { total_credits, total_usage } }`). | ||
|
|
||
| ## Tests | ||
|
|
||
| ```bash | ||
| pnpm --filter @corsair-dev/openrouter test | ||
| ``` | ||
|
|
||
| - Offline schema + mocked-client handler tests always run (no API key). | ||
| - Live client tests run only when `OPENROUTER_API_KEY` is set. | ||
|
|
||
| ## Working proof | ||
|
|
||
| The PR's live recording exercises the integration against OpenRouter: | ||
| https://www.loom.com/share/5e7438d01bac4f76b6bcc351950b0f8b | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.