crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

feat(llms): add OrcaRouter as native OpenAI-compatible provider

Open xilema2 opened this issue 6 months ago • 3 comments

Summary

Adds OrcaRouter — an adaptive LLM router with ~120 chat models across OpenAI / Anthropic / Google / DeepSeek / xAI / Qwen / MiniMax / Kimi / Z-AI — as a native OpenAI-compatible provider, alongside the ones added in #5042 (OpenRouter, DeepSeek, Ollama, vLLM, Cerebras, Dashscope).

Disclosure: I'm an engineer on the OrcaRouter team.

Architecture

Reuses the data-driven OpenAICompatibleCompletion machinery from #5042 — one new entry in OPENAI_COMPATIBLE_PROVIDERS plus the matching wire-ups in LLM.__new__ routing. No new classes, no new abstractions.

Provider

Field Value
API base URL https://api.orcarouter.ai/v1
API key env ORCAROUTER_API_KEY
Base URL env ORCAROUTER_API_BASE_URL (optional)
Attribution HTTP-Referer: https://crewai.com + X-Title: crewai
Docs https://docs.orcarouter.ai
Models catalog https://www.orcarouter.ai/models

Usage

from crewai import LLM

# OpenAI via OrcaRouter
llm = LLM(model="orcarouter/openai/gpt-5")

# Anthropic via OrcaRouter
llm = LLM(model="orcarouter/anthropic/claude-opus-4.7")

# Adaptive router — OrcaRouter picks the best upstream per request
llm = LLM(model="orcarouter/auto")

# Explicit provider form
llm = LLM(model="openai/gpt-5", provider="orcarouter")


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  * Added support for the OrcaRouter LLM provider; models can be instantiated with the orcarouter/ prefix or via explicit provider selection
  * OrcaRouter registered as OpenAI-compatible with configurable API endpoint, credentials, and default attribution headers

* **Tests**
  * Added coverage verifying OrcaRouter configuration, routing behavior, header values, and environment-based base-URL override

<!-- review_stack_entry_start -->

[![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/crewAIInc/crewAI/pull/5860?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

xilema2 avatar May 19 '26 06:05 xilema2

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a345d64b-14c9-4ecc-8119-60a8042a4c16

📥 Commits

Reviewing files that changed from the base of the PR and between 17a5cd148c4a89da83ea017b5b276e1958a636f3 and b70e90648c485873be775a8060519473aa0b5879.

📒 Files selected for processing (1)
  • lib/crewai/tests/llms/openai_compatible/test_openai_compatible.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/crewai/tests/llms/openai_compatible/test_openai_compatible.py

📝 Walkthrough

Walkthrough

Adds OrcaRouter (orcarouter) as a supported provider: LLM routing recognizes orcarouter/... prefixes, provider matching and routing treat orcarouter as OpenAI-compatible, its provider config is registered, and integration tests exercise routing and env overrides.

Changes

OrcaRouter provider support

Layer / File(s) Summary
LLM routing logic for OrcaRouter
lib/crewai/src/crewai/llm.py
Extends SUPPORTED_NATIVE_PROVIDERS to include orcarouter, maps orcarouter/... prefix in LLM.__new__, adds _matches_provider_pattern handling for orcarouter, and includes orcarouter in OpenAI-compatible routing via _get_native_provider.
OpenAI-compatible provider registration
lib/crewai/src/crewai/llms/providers/openai_compatible/completion.py
Adds orcarouter entry to OPENAI_COMPATIBLE_PROVIDERS with default base_url, API key and base-url override env var names, required-key behavior, default attribution headers, and updates OpenAICompatibleCompletion docstring.
Provider registry and integration tests
lib/crewai/tests/llms/openai_compatible/test_openai_compatible.py
Adds tests asserting OrcaRouter registry configuration, LLM→OpenAICompatibleCompletion creation for orcarouter/..., orcarouter/auto, explicit provider="orcarouter", attribution header constants, and ORCAROUTER_API_BASE_URL override behavior.

Sequence Diagram

sequenceDiagram
  participant LLM
  participant ProviderRegistry
  participant OpenAICompatibleCompletion
  LLM->>ProviderRegistry: request provider for "orcarouter/..."
  ProviderRegistry->>LLM: provider="orcarouter", ProviderConfig(base_url, headers, env keys)
  LLM->>OpenAICompatibleCompletion: create client with provider config
  OpenAICompatibleCompletion->>LLM: return configured completion client

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A new router hops into the fold,
Named Orca, steady and bold.
Headers set and tests in place,
It joins the crew—quick, neat, and chaste.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: adding OrcaRouter as a native OpenAI-compatible provider to the LLMs module.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar May 19 '26 06:05 coderabbitai[bot]

Addressed CodeRabbit's suggestion in b70e9064 — added test_llm_creates_openai_compatible_for_orcarouter_with_explicit_provider to cover the explicit provider="orcarouter" kwarg routing path separately from the prefix-based orcarouter/<model> branch already covered by test_llm_creates_openai_compatible_for_orcarouter. All 6 OrcaRouter tests pass locally.

xilema2 avatar May 19 '26 10:05 xilema2

Hi @caike, gentle ping on this PR. As a first-time contributor, the required CI workflows are waiting for maintainer approval to run (5 workflows pending). Could you kindly approve them when you have a moment? A re-review would also be appreciated once CI passes. Thanks!

xilema2 avatar May 21 '26 03:05 xilema2