instructor
instructor copied to clipboard
feat(orcarouter): add OrcaRouter provider integration
Describe your changes
Adds OrcaRouter as a first-class provider. OrcaRouter is an OpenAI-compatible meta-router that exposes 150+ chat models from OpenAI, Anthropic, Google, DeepSeek, Qwen, MiniMax, xAI, Kimi, and others behind a single API key, with adaptive routing strategies (cheapest / balanced / quality / adaptive / gated_adaptive) that balance cost, latency, and quality per request.
The integration mirrors the existing OpenRouter provider exactly — it reuses the shared OpenAI-compatible request/response handlers and only adds the provider-specific identity, factory, and routing entry points.
Usage:
import instructor
from pydantic import BaseModel
class User(BaseModel):
name: str
age: int
client = instructor.from_provider("orcarouter/openai/gpt-4o-mini")
user = client.create(
messages=[{"role": "user", "content": "Ivan is 27"}],
response_model=User,
)
What changed:
Provider.ORCAROUTERenum value +Mode.ORCAROUTER_STRUCTURED_OUTPUTSlegacy mode (normalised toJSON_SCHEMA, mirroringOPENROUTER_STRUCTURED_OUTPUTS)- New
instructor/v2/providers/orcarouter/package withfrom_orcarouterfactory andOrcaRouterJSONSchemaHandler(delegates to the shared OpenAI-compat structured-output handler) Provider.ORCAROUTERadded toOPENAI_COMPAT_PROVIDERSandOPENAI_PARALLEL_TOOL_PROVIDERSsoTOOLS,MD_JSON,JSON, andPARALLEL_TOOLShandlers are registered automatically- Provider spec registered in
provider_specs.py; URL detection inget_provider()matchesorcarouterin the base URL _build_orcarouteradded toauto_client.pysoinstructor.from_provider("orcarouter/<model>")works with theORCAROUTER_API_KEYenv var andhttps://api.orcarouter.ai/v1as the default base URL- Documentation in
docs/integrations/orcarouter.md(linked frommkdocs.yml) - Tests in
tests/llm/test_orcarouter/test_wiring.py(no API key required, plus a skipif-guarded live smoke test) - Updated
tests/test_utils.py::test_get_provider_matches_supported_providersandtests/v2/test_client_unified.pyhandler-path map so the existing parity tests still cover the new provider CHANGELOG.mdentry under[Unreleased]
Local verification:
pytest tests/llm/test_orcarouter/— 13 passed, 1 skipped (live smoke test skipped whenORCAROUTER_API_KEYis unset)pytest tests/test_utils.py::test_get_provider_matches_supported_providers tests/v2/test_client_unified.py— all passingruff check— clean
Disclosure: I'm an engineer on the OrcaRouter team.
Issue ticket number and link
N/A — new provider addition.
Checklist before requesting a review
- [x] I have performed a self-review of my code
- [x] If it is a core feature, I have added thorough tests.
- [x] If it is a core feature, I have added documentation.