|
| 1 | +--- |
| 2 | +title: "OrcaRouter" |
| 3 | +id: integrations-orcarouter |
| 4 | +description: "OrcaRouter integration for Haystack" |
| 5 | +slug: "/integrations-orcarouter" |
| 6 | +--- |
| 7 | + |
| 8 | + |
| 9 | +## haystack_integrations.components.generators.orcarouter.chat.chat_generator |
| 10 | + |
| 11 | +### OrcaRouterChatGenerator |
| 12 | + |
| 13 | +Bases: <code>OpenAIChatGenerator</code> |
| 14 | + |
| 15 | +Enables text generation using OrcaRouter generative models. |
| 16 | + |
| 17 | +OrcaRouter is an OpenAI-compatible model routing gateway that exposes 100+ chat models from providers such as |
| 18 | +OpenAI, Anthropic, Google, DeepSeek, and Qwen behind a single endpoint and API key. Models are addressed with a |
| 19 | +`provider/model` namespace (for example `openai/gpt-4o-mini` or `anthropic/claude-opus-4.8`). The special |
| 20 | +`orcarouter/auto` router selects an upstream model per request according to the routing policy configured in your |
| 21 | +OrcaRouter console. |
| 22 | + |
| 23 | +For the list of supported models, see the [OrcaRouter model catalog](https://www.orcarouter.ai/models). |
| 24 | + |
| 25 | +This component supports streaming, tool-calling, and structured outputs. |
| 26 | +It uses the ChatMessage format for both input and output; see the |
| 27 | +[Haystack docs](https://docs.haystack.deepset.ai/docs/chatmessage) for details. |
| 28 | + |
| 29 | +Usage example: |
| 30 | + |
| 31 | +```python |
| 32 | +from haystack_integrations.components.generators.orcarouter import OrcaRouterChatGenerator |
| 33 | +from haystack.dataclasses import ChatMessage |
| 34 | + |
| 35 | +messages = [ChatMessage.from_user("What's Natural Language Processing?")] |
| 36 | + |
| 37 | +client = OrcaRouterChatGenerator(model="openai/gpt-4o-mini") |
| 38 | +response = client.run(messages) |
| 39 | +print(response) |
| 40 | +``` |
| 41 | + |
| 42 | +#### __init__ |
| 43 | + |
| 44 | +```python |
| 45 | +__init__( |
| 46 | + *, |
| 47 | + api_key: Secret = Secret.from_env_var("ORCAROUTER_API_KEY"), |
| 48 | + model: str = "openai/gpt-4o-mini", |
| 49 | + streaming_callback: StreamingCallbackT | None = None, |
| 50 | + api_base_url: str | None = "https://api.orcarouter.ai/v1", |
| 51 | + organization: str | None = None, |
| 52 | + generation_kwargs: dict[str, Any] | None = None, |
| 53 | + tools: ToolsType | None = None, |
| 54 | + tools_strict: bool = False, |
| 55 | + timeout: float | None = None, |
| 56 | + max_retries: int | None = None, |
| 57 | + http_client_kwargs: dict[str, Any] | None = None |
| 58 | +) -> None |
| 59 | +``` |
| 60 | + |
| 61 | +Creates an instance of OrcaRouterChatGenerator. |
| 62 | + |
| 63 | +Unless specified otherwise, the default model is `openai/gpt-4o-mini`. |
| 64 | + |
| 65 | +**Parameters:** |
| 66 | + |
| 67 | +- **api_key** (<code>Secret</code>) – The OrcaRouter API key. |
| 68 | +- **model** (<code>str</code>) – The name of the OrcaRouter chat completion model to use. Models use a `provider/model` namespace |
| 69 | + (for example `openai/gpt-4o-mini`). Use `orcarouter/auto` to let OrcaRouter route the request. |
| 70 | +- **streaming_callback** (<code>StreamingCallbackT | None</code>) – A callback function that is called when a new token is received from the stream. |
| 71 | + The callback function accepts StreamingChunk as an argument. |
| 72 | +- **api_base_url** (<code>str | None</code>) – The OrcaRouter API base URL. For more details, see the OrcaRouter |
| 73 | + [documentation](https://docs.orcarouter.ai). |
| 74 | +- **organization** (<code>str | None</code>) – Your OrcaRouter organization ID, if any. |
| 75 | +- **generation_kwargs** (<code>dict\[str, Any\] | None</code>) – Other parameters to use for the model. These parameters are sent directly to the OrcaRouter endpoint. |
| 76 | + See OrcaRouter [API docs](https://docs.orcarouter.ai) for more details. Some of the supported parameters: |
| 77 | +- `max_tokens`: The maximum number of tokens the output text can have. |
| 78 | +- `temperature`: The sampling temperature to use. Higher values mean the model takes more risks. |
| 79 | +- `top_p`: The nucleus sampling value to use. |
| 80 | +- `stream`: Whether to stream back partial progress. |
| 81 | +- `extra_body`: A dictionary of OrcaRouter-specific routing preferences (such as a fallback list of |
| 82 | + models) that is passed straight through to the gateway. |
| 83 | +- **tools** (<code>ToolsType | None</code>) – A list of tools or a Toolset for which the model can prepare calls. This parameter can accept either a |
| 84 | + list of `Tool` objects or a `Toolset` instance. |
| 85 | +- **tools_strict** (<code>bool</code>) – Whether to enable strict schema adherence for tool calls. If set to `True`, the model follows exactly |
| 86 | + the schema provided in the `parameters` field of the tool definition. |
| 87 | +- **timeout** (<code>float | None</code>) – The timeout for the OrcaRouter API call. |
| 88 | +- **max_retries** (<code>int | None</code>) – Maximum number of retries to contact OrcaRouter after an internal error. |
| 89 | + If not set, it defaults to either the `OPENAI_MAX_RETRIES` environment variable, or set to 5. |
| 90 | +- **http_client_kwargs** (<code>dict\[str, Any\] | None</code>) – A dictionary of keyword arguments to configure a custom `httpx.Client`or `httpx.AsyncClient`. |
| 91 | + For more information, see the [HTTPX documentation](https://www.python-httpx.org/api/#client). |
0 commit comments