instructor icon indicating copy to clipboard operation
instructor copied to clipboard

feat(orcarouter): add OrcaRouter provider integration

Open xilema2 opened this issue 6 months ago • 0 comments

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.ORCAROUTER enum value + Mode.ORCAROUTER_STRUCTURED_OUTPUTS legacy mode (normalised to JSON_SCHEMA, mirroring OPENROUTER_STRUCTURED_OUTPUTS)
  • New instructor/v2/providers/orcarouter/ package with from_orcarouter factory and OrcaRouterJSONSchemaHandler (delegates to the shared OpenAI-compat structured-output handler)
  • Provider.ORCAROUTER added to OPENAI_COMPAT_PROVIDERS and OPENAI_PARALLEL_TOOL_PROVIDERS so TOOLS, MD_JSON, JSON, and PARALLEL_TOOLS handlers are registered automatically
  • Provider spec registered in provider_specs.py; URL detection in get_provider() matches orcarouter in the base URL
  • _build_orcarouter added to auto_client.py so instructor.from_provider("orcarouter/<model>") works with the ORCAROUTER_API_KEY env var and https://api.orcarouter.ai/v1 as the default base URL
  • Documentation in docs/integrations/orcarouter.md (linked from mkdocs.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_providers and tests/v2/test_client_unified.py handler-path map so the existing parity tests still cover the new provider
  • CHANGELOG.md entry under [Unreleased]

Local verification:

  • pytest tests/llm/test_orcarouter/ — 13 passed, 1 skipped (live smoke test skipped when ORCAROUTER_API_KEY is unset)
  • pytest tests/test_utils.py::test_get_provider_matches_supported_providers tests/v2/test_client_unified.py — all passing
  • ruff 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.

xilema2 avatar May 27 '26 06:05 xilema2