> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Multi-Provider Agents

> Build agents that work with OpenAI, Anthropic, Google, and 30+ LLM providers

Switch between any LLM provider — OpenAI, Anthropic, Google, and more — without changing your agent code.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Multi-Provider Routing"
        A[🤖 Agent] --> R{🔀 Router}
        R -->|openai/...| O[🟢 OpenAI]
        R -->|anthropic/...| C[🟣 Anthropic]
        R -->|google/...| G[🔵 Google]
        R -->|other/...| X[⚡ Any Provider]
    end

    classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef router fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef provider fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef other fill:#10B981,stroke:#7C90A0,color:#fff

    class A agent
    class R router
    class O,C,G provider
    class X other
    classDef agent fill:#8B0000,color:#fff
    classDef tool fill:#189AB4,color:#fff
```

## Quick Start

<Steps>
  <Step title="Simple Usage">
    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    npm install praisonai
    ```
  </Step>

  <Step title="With Configuration">
    ```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    import { Agent } from 'praisonai';

    const agent = new Agent({
      instructions: 'You are a helpful assistant.',
      llm: 'openai/gpt-4o-mini'
    });

    const response = await agent.chat('Hello, how are you?');
    console.log(response);
    ```
  </Step>

  <Step title="Switch Providers with One Line">
    ```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    import { Agent } from 'praisonai';

    const agent = new Agent({
      instructions: 'You are a helpful assistant.',
      llm: 'anthropic/claude-3-5-sonnet-latest'
    });

    const response = await agent.chat('Explain AI in one sentence');
    console.log(response);
    ```
  </Step>
</Steps>

***

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant Router as Backend Router
    participant LLM as LLM Provider

    User->>Agent: chat("question")
    Agent->>Router: Resolve backend for llm string
    Router-->>Agent: AI SDK or Native provider
    Agent->>LLM: API request
    LLM-->>Agent: Response
    Agent-->>User: Answer
```

***

## Model String Resolution

PraisonAI resolves a model string in three tiers: **explicit prefix > prefix inference > OpenAI fallback**.

| `llm` string                         | `baseURL` set? | Resolved provider | Backend used                  |
| ------------------------------------ | -------------- | ----------------- | ----------------------------- |
| `gpt-4o-mini`                        | no             | openai            | OpenAI (native)               |
| `claude-3-5-sonnet-latest`           | no             | **anthropic**     | **AI SDK**                    |
| `gemini-2.0-flash`                   | no             | **google**        | **AI SDK**                    |
| `openai/gpt-4o`                      | no             | openai            | OpenAI (native)               |
| `anthropic/claude-3-5-sonnet-latest` | no             | anthropic         | AI SDK                        |
| `claude-3-5-sonnet-latest`           | **yes**        | openai            | OpenAI-compatible (baseURL)   |
| `anthropic/claude-3-5-sonnet-latest` | **yes**        | **anthropic**     | AI SDK (explicit prefix wins) |

A bare name plus a custom `baseURL` stays on the OpenAI-compatible path — see [The baseURL exception](/docs/js/model-routing#the-baseurl-exception).

***

## Supported Providers

| Provider  | Model String      | Example                               |
| --------- | ----------------- | ------------------------------------- |
| OpenAI    | `openai/model`    | `openai/gpt-4o`, `openai/gpt-4o-mini` |
| Anthropic | `anthropic/model` | `anthropic/claude-3-5-sonnet-latest`  |
| Google    | `google/model`    | `google/gemini-2.0-flash`             |
| Groq      | `groq/model`      | `groq/llama-3.3-70b-versatile`        |
| Mistral   | `mistral/model`   | `mistral/mistral-large-latest`        |
| Cohere    | `cohere/model`    | `cohere/command-r-plus`               |
| DeepSeek  | `deepseek/model`  | `deepseek/deepseek-chat`              |
| xAI       | `xai/model`       | `xai/grok-2`                          |

***

## Common Patterns

### Agent with Tools

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { Agent } from 'praisonai';

function getWeather(city: string): string {
  return JSON.stringify({ city, temperature: 22, condition: 'sunny' });
}

const agent = new Agent({
  instructions: 'You help users check the weather.',
  llm: 'anthropic/claude-3-5-sonnet-latest',
  tools: [getWeather]
});

const response = await agent.chat('What is the weather in Paris?');
console.log(response);
```

Tools work identically on every provider — swap the `llm` string (`openai/...`, `google/...`, `groq/...`, `ollama/...`) with no other code change.

### Structured Output

`outputSchema` takes a JSON Schema object (not a Zod schema) and constrains the model to matching JSON on **every provider**. OpenAI uses native `response_format: json_schema`; other providers (Anthropic, Google, Groq, Mistral, Ollama, …) route through the AI SDK backend's `generateObject({ schema })`. See [Structured Output](/docs/js/structured-output).

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { Agent } from 'praisonai';

const agent = new Agent({
  instructions: 'Extract person information from text.',
  llm: 'openai/gpt-4o-mini',
  outputSchema: {
    type: 'object',
    properties: {
      name: { type: 'string' },
      age: { type: 'number' },
      city: { type: 'string' },
    },
    required: ['name', 'age', 'city']
  },
  outputSchemaName: 'Person'  // names the schema in the response_format payload
});

const result = await agent.chat('John is 30 years old and lives in Paris');
// '{"name":"John","age":30,"city":"Paris"}'
```

<Note>
  `outputSchema` works on every provider from PraisonAI PR #4412 onward. Reasoning families (`gpt-5*`, `o1*`, `o3*`, `o4*`) still omit `temperature` automatically. See [Output → Schema-constrained output](/docs/js/output#schema-constrained-output-outputschema).
</Note>

### Multi-Agent Pipeline

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { Agent } from 'praisonai';

const researcher = new Agent({
  name: 'researcher',
  instructions: 'Research topics thoroughly.',
  llm: 'anthropic/claude-3-5-sonnet-latest'
});

const writer = new Agent({
  name: 'writer',
  instructions: 'Write engaging content based on research.',
  llm: 'openai/gpt-4o'
});

const research = await researcher.chat('Research the history of AI');
const article = await writer.chat(`Write an article based on: ${research}`);
console.log(article);
```

### Environment Variables

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
export OPENAI_API_KEY=sk-...
export ANTHROPIC_API_KEY=sk-ant-...
export GOOGLE_API_KEY=AIza...
export GROQ_API_KEY=gsk_...

# Or pass apiKey per-agent (as of PR #4483, honoured across all providers)

# Override backend resolver
export PRAISONAI_BACKEND=ai-sdk   # Force AI SDK for all providers
export PRAISONAI_BACKEND=native   # Force native providers only
export PRAISONAI_BACKEND=auto     # Auto-select (default)
```

***

## Best Practices

<AccordionGroup>
  <Accordion title="Use the provider/model string format">
    Always use `"provider/model"` strings (`"openai/gpt-4o-mini"`) rather than provider-specific config objects. Switching providers is a one-line change.
  </Accordion>

  <Accordion title="Install provider packages only when needed">
    Core PraisonAI bundles OpenAI support. For other providers install `@ai-sdk/anthropic`, `@ai-sdk/google`, etc. only when you use them.
  </Accordion>

  <Accordion title="Match model to task">
    For quick tasks use `openai/gpt-4o-mini` or `google/gemini-2.0-flash`. For complex reasoning use `anthropic/claude-3-5-sonnet-latest` or `openai/gpt-4o`. Mix providers across agents in multi-agent workflows.
  </Accordion>

  <Accordion title="Store API keys in environment variables">
    Never hard-code API keys. Use environment variables (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, etc.). For production deployments use a secrets manager.
  </Accordion>
</AccordionGroup>

***

## Related

<CardGroup cols={2}>
  <Card title="Providers" icon="plug" href="/docs/js/providers">
    Full provider reference and configuration
  </Card>

  <Card title="Structured Output" icon="code" href="/docs/js/structured-output">
    Type-safe JSON responses
  </Card>
</CardGroup>
