Skip to content

feat: add OrcaRouter as a first-class language model provider - #431

Open
kuswardhanietidims-svg wants to merge 1 commit into
microsoft:mainfrom
kuswardhanietidims-svg:feat/orcarouter-provider
Open

feat: add OrcaRouter as a first-class language model provider#431
kuswardhanietidims-svg wants to merge 1 commit into
microsoft:mainfrom
kuswardhanietidims-svg:feat/orcarouter-provider

Conversation

@kuswardhanietidims-svg

Copy link
Copy Markdown

Motivation

TypeChat makes it easy to build natural language interfaces using types — but to talk to an LLM you still need a model. Today, createLanguageModel only knows about the OpenAI and Azure OpenAI providers, which locks users into a single vendor's endpoint.

OrcaRouter is an OpenAI-compatible AI gateway built for both models and agents. Like OpenRouter, it exposes a provider/model namespace across many models — but it also combines adaptive routing, automatic failover, zero-markup inference, observability, guardrails, and agent-tool governance behind the same endpoint. Adding orcarouter as a first-class provider means TypeChat users can use that whole stack directly, without treating OrcaRouter as an anonymous custom base URL.

It also runs gateway-level, zero-trust security for AI agents on the same endpoint — screening every prompt/response and governing every tool call on a default-deny basis, with no application code changes.

Changes

  • typescript/src/model.ts — new createOrcaRouterLanguageModel factory that reuses the existing OpenAI-compatible Chat Completions client (same as createOpenAILanguageModel) pointed at https://api.orcarouter.ai/v1/chat/completions, plus ORCAROUTER_API_KEY / ORCAROUTER_MODEL / ORCAROUTER_ENDPOINT routing in createLanguageModel.
  • python/src/typechat/_internal/model.py — matching create_orca_router_language_model factory and ORCAROUTER_API_KEY routing in create_language_model, exported from typechat/__init__.py.
  • Tests — TypeScript (typescript/tests/model.test.mjs) and Python (python/tests/test_model.py) coverage for the new factory and env routing, mirroring the existing OpenAI provider tests.
  • Docs.env.example, the TypeScript and Python basic-usage pages, and the examples env-var table now list OrcaRouter alongside OpenAI and Azure OpenAI.

Validation

  • npm test in typescript/: 118 tests pass (113 baseline + 5 new OrcaRouter tests).
  • pytest in python/: 21 passed, 3 skipped (pre-existing skips).
  • pyright in python/: no new errors introduced (55 pre-existing errors on main, unchanged).
  • eleventy site build succeeds with the updated docs.
  • Live test against a real key through the new createOrcaRouterLanguageModel code path (and through createLanguageModel with ORCAROUTER_API_KEY set) returned HTTP 200 with a valid completion.

Discord: discord.gg/YEubt8enRA · X: https://x.com/OrcaRouter

I'm an engineer on the OrcaRouter team.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds OrcaRouter as a first-class, OpenAI-compatible language model provider across the TypeScript and Python TypeChat SDKs, including environment-variable routing, tests, and documentation updates.

Changes:

  • Add OrcaRouter language model factories (createOrcaRouterLanguageModel / create_orca_router_language_model) and route via createLanguageModel / create_language_model when ORCAROUTER_API_KEY is set.
  • Add TypeScript and Python tests covering OrcaRouter factory behavior and env-var routing (including endpoint override).
  • Update docs and .env.example to document OrcaRouter configuration alongside OpenAI and Azure OpenAI.
Show a summary per file
File Description
typescript/tests/model.test.mjs Adds routing + factory tests for OrcaRouter in the TS test suite.
typescript/src/model.ts Implements OrcaRouter factory and extends env-var routing to include OrcaRouter.
site/src/docs/typescript/basic-usage.md Documents OrcaRouter usage in TypeScript basics page.
site/src/docs/python/basic-usage.md Documents OrcaRouter usage in Python basics page.
site/src/docs/examples.md Updates examples documentation to include OrcaRouter environment variables.
python/tests/test_model.py Adds tests for the OrcaRouter factory behavior in Python.
python/src/typechat/_internal/model.py Implements OrcaRouter factory and extends env-var routing in Python.
python/src/typechat/init.py Exports the new OrcaRouter factory from the public Python package API.
.env.example Adds OrcaRouter env-var templates (including optional endpoint override).

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 9/9 changed files
  • Comments generated: 5
  • Review effort level: Lite

Comment thread site/src/docs/typescript/basic-usage.md Outdated
Comment on lines +71 to +75
export function createOpenAILanguageModel(apiKey: string, model: string, endPoint? string): TypeChatLanguageModel;

export function createAzureOpenAILanguageModel(apiKey: string, endPoint: string): TypeChatLanguageModel;

export function createOrcaRouterLanguageModel(apiKey: string, model: string, endPoint? string): TypeChatLanguageModel;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — the signature now reads endPoint?: string in the trimmed docs-only PR.

Comment thread site/src/docs/python/basic-usage.md Outdated
For even more convenience, TypeChat also provides a function to infer which
provider you're using.

```ts

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — the fence for create_language_model is now py instead of ts.

Comment thread site/src/docs/examples.md Outdated
Comment on lines +85 to +88
| Variable | Value |
|----------|-------|
| `ORCAROUTER_MODEL` | The OrcaRouter model name (e.g. `orcarouter/auto` or `orcarouter/free`) |
| `ORCAROUTER_API_KEY` | Your OrcaRouter API key |

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded — per maintainer feedback the OrcaRouter-specific ORCAROUTER_ENDPOINT variable was removed; the docs now use the existing OPENAI_ENDPOINT variable for OpenAI-compatible gateways.

Comment thread python/src/typechat/__init__.py Outdated
# SPDX-License-Identifier: MIT

from typechat._internal.model import PromptSection, TypeChatLanguageModel, create_language_model, create_openai_language_model, create_azure_openai_language_model
from typechat._internal.model import PromptSection, TypeChatLanguageModel, create_language_model, create_openai_language_model, create_azure_openai_language_model, create_orca_router_language_model

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer applicable — the OrcaRouter export was removed from python/src/typechat/__init__.py; the file is back to baseline.

Comment thread python/src/typechat/_internal/model.py Outdated
Comment on lines +189 to +193
@@ -187,8 +190,13 @@ def required_var(name: str) -> str:
api_key=required_var("AZURE_OPENAI_API_KEY")
endpoint=required_var("AZURE_OPENAI_ENDPOINT")
return create_azure_openai_language_model(api_key, endpoint)
elif "ORCAROUTER_API_KEY" in vals:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer applicable — the OrcaRouter routing branch was removed from python/src/typechat/_internal/model.py; the file is back to baseline.

@robgruen

Copy link
Copy Markdown
Contributor

Thanks for the contribution and for the clear disclosure.

TypeChat already supports OrcaRouter today via the endPoint parameter on createOpenAILanguageModel / create_openai_language_model — your own quickstart's base-URL swap maps directly onto it. Adding named factories per OpenAI-compatible gateway isn't a direction we want to take, since it commits us to maintaining third-party endpoints in shipped packages and sets a precedent we'd have to extend to a dozen other providers. We'd welcome a trimmed PR that adds a vendor-neutral 'using an OpenAI-compatible gateway' docs section instead, with OrcaRouter as one of the named examples."

@robgruen robgruen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my *vendor neutral" doc comment on the PR summary.

Adds a vendor-neutral "Using OpenAI-compatible gateways" section to the
TypeScript and Python basic-usage pages and the examples env-var guide.
OpenAI-compatible services (e.g. OrcaRouter, OpenRouter) can be used via
the existing endPoint parameter / OPENAI_ENDPOINT variable, so no new
provider-specific factories or env-var routing are needed.

Co-Authored-By: Claude <noreply@anthropic.com>
@kuswardhanietidims-svg

Copy link
Copy Markdown
Author

Thanks for the feedback and the clear direction. I've trimmed the PR to match:

  • Removed the OrcaRouter-specific factories (createOrcaRouterLanguageModel / create_orca_router_language_model), the ORCAROUTER_* env-var routing in createLanguageModel / create_language_model, and the associated tests and exports.
  • Added a vendor-neutral "Using OpenAI-compatible gateways" section to the TypeScript and Python basic-usage docs and the examples env-var guide. It shows the existing endPoint parameter and OPENAI_ENDPOINT variable, with OrcaRouter as one named example (alongside OpenRouter), and I also fixed the endPoint? string signature typo in the TypeScript snippet.

The full diff is now docs-only across three files. The site builds cleanly with npm run build (eleventy).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants