|
| 1 | +# Model Providers |
| 2 | + |
| 3 | +An oya `Agent` takes a `model`. oya ships three provider adapters — Anthropic, |
| 4 | +OpenAI, and Google — each a small function that returns a `LanguageModel`. They're |
| 5 | +interchangeable: the rest of your agent (tools, instructions, `generate` / |
| 6 | +`stream`) stays identical no matter which one plans. |
| 7 | + |
| 8 | +Each provider is a separate entry point, so you only pull in what you use: |
| 9 | + |
| 10 | +```ts |
| 11 | +import { anthropic } from "oyadotai/anthropic"; |
| 12 | +import { openai } from "oyadotai/openai"; |
| 13 | +import { google } from "oyadotai/google"; |
| 14 | +``` |
| 15 | + |
| 16 | +## Anthropic |
| 17 | + |
| 18 | +Reads `ANTHROPIC_API_KEY` from the environment unless you pass `apiKey`. |
| 19 | + |
| 20 | +```ts |
| 21 | +import { Agent, createTool } from "oyadotai"; |
| 22 | +import { anthropic } from "oyadotai/anthropic"; |
| 23 | + |
| 24 | +const agent = new Agent({ |
| 25 | + model: anthropic("claude-haiku-4-5-20251001"), |
| 26 | + tools: { get_weather: getWeather }, |
| 27 | +}); |
| 28 | + |
| 29 | +const { text } = await agent.generate("How's the weather in NYC?"); |
| 30 | +``` |
| 31 | + |
| 32 | +## OpenAI |
| 33 | + |
| 34 | +Reads `OPENAI_API_KEY` from the environment unless you pass `apiKey`. |
| 35 | + |
| 36 | +```ts |
| 37 | +import { Agent } from "oyadotai"; |
| 38 | +import { openai } from "oyadotai/openai"; |
| 39 | + |
| 40 | +const agent = new Agent({ |
| 41 | + model: openai("gpt-4o"), |
| 42 | + tools: { get_weather: getWeather }, |
| 43 | +}); |
| 44 | +``` |
| 45 | + |
| 46 | +## Google |
| 47 | + |
| 48 | +Reads `GEMINI_API_KEY` (or `GOOGLE_API_KEY`) from the environment unless you pass |
| 49 | +`apiKey`. |
| 50 | + |
| 51 | +```ts |
| 52 | +import { Agent } from "oyadotai"; |
| 53 | +import { google } from "oyadotai/google"; |
| 54 | + |
| 55 | +const agent = new Agent({ |
| 56 | + model: google("gemini-2.5-pro"), |
| 57 | + tools: { get_weather: getWeather }, |
| 58 | +}); |
| 59 | +``` |
| 60 | + |
| 61 | +## Passing the key explicitly |
| 62 | + |
| 63 | +Every provider accepts an options object with `apiKey`, so you don't have to rely |
| 64 | +on environment variables — useful in serverless or multi-tenant setups: |
| 65 | + |
| 66 | +```ts |
| 67 | +anthropic("claude-haiku-4-5-20251001", { apiKey: process.env.MY_ANTHROPIC_KEY }); |
| 68 | +openai("gpt-4o", { apiKey: myKey }); |
| 69 | +google("gemini-2.5-pro", { apiKey: myKey }); |
| 70 | +``` |
| 71 | + |
| 72 | +If no key is found, the provider throws a clear error naming the environment |
| 73 | +variable to set. |
| 74 | + |
| 75 | +## Swapping providers |
| 76 | + |
| 77 | +Because the provider is just the `model` value, switching is a one-line change — |
| 78 | +your tools, instructions, and the plan-once execution model are unchanged: |
| 79 | + |
| 80 | +```diff |
| 81 | +- model: anthropic("claude-haiku-4-5-20251001"), |
| 82 | ++ model: openai("gpt-4o"), |
| 83 | +``` |
| 84 | + |
| 85 | +The model only ever emits the plan; from there the runtime executes the DAG the |
| 86 | +same way regardless of which provider planned it. See |
| 87 | +[Projection Types](/concepts/projection-types) for what the model does and doesn't |
| 88 | +get to see. |
0 commit comments