> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Portkey

> Use Portkey AI Gateway for multi-provider routing with Agno agents.

Portkey is an AI Gateway that provides a unified interface to access multiple AI providers with advanced features like routing, load balancing, retries, and observability. Use Portkey to build production-ready AI applications with better reliability and cost optimization.

With Portkey, you can:

* Route requests across multiple AI providers
* Implement fallback mechanisms for better reliability
* Monitor and analyze your AI usage
* Cache responses for cost optimization
* Apply rate limiting and usage controls

## Authentication

You need both a Portkey API key and a virtual key for model routing. Get them [from Portkey here](https://app.portkey.ai/).

```bash Mac theme={null}
export PORTKEY_API_KEY=***
export PORTKEY_VIRTUAL_KEY=***
```

```bash Windows theme={null}
setx PORTKEY_API_KEY ***
setx PORTKEY_VIRTUAL_KEY ***
```

## Example

Install the `portkey-ai` and `openai` packages:

```shell theme={null}
uv pip install -U agno portkey-ai openai
```

Use `Portkey` with your `Agent`:

```python agent.py theme={null}
import os

from agno.agent import Agent
from agno.models.portkey import Portkey

agent = Agent(
    model=Portkey(id="gpt-5-mini", portkey_api_key=os.getenv("PORTKEY_API_KEY")),
    markdown=True
)

# Print the response in the terminal
agent.print_response("What is Portkey and why would I use it as an AI gateway?")
```

## Advanced Configuration

You can configure Portkey with custom routing and retry policies:

```python theme={null}
import os

from agno.agent import Agent
from agno.models.portkey import Portkey

config = {
    "strategy": {
        "mode": "fallback"
    },
    "targets": [
        {"virtual_key": "openai-key"},
        {"virtual_key": "anthropic-key"}
    ]
}

agent = Agent(
    model=Portkey(
        id="gpt-5-mini",
        config=config,
        portkey_api_key=os.getenv("PORTKEY_API_KEY"),
    ),
)
```

> [!NOTE]
>
> View more examples [here](https://agno-v2.mintlify.site/models/providers/gateways/portkey/usage/basic-stream.md).

## Params

| Parameter | Type | Default | Description |
| - | - | - | - |
| `id` | `str` | `"gpt-4o-mini"` | The id of the model to use through Portkey |
| `name` | `str` | `"Portkey"` | The name of the model |
| `provider` | `str` | `"Portkey"` | The provider of the model |
| `portkey_api_key` | `Optional[str]` | `None` | The API key for Portkey. Set it explicitly on the model; there is no environment variable fallback |
| `base_url` | `str` | `"https://api.portkey.ai/v1"` | The base URL for the Portkey API |
| `virtual_key` | `Optional[str]` | `None` | The virtual key for the underlying provider. Falls back to the `PORTKEY_VIRTUAL_KEY` environment variable if not set |
| `config` | `Optional[Dict[str, Any]]` | `None` | Portkey configuration (routing, retries, etc.) |

`Portkey` also supports the params of [OpenAI](https://agno-v2.mintlify.site/reference/models/openai.md).

> [!TIP]
>
> The `base_url` parameter is the endpoint for the Portkey AI Gateway.
> Default value is "[https://api.portkey.ai/v1](https://api.portkey.ai/v1)" for the standard managed Portkey service.
>
> You only need to specify this if you are using a self-hosted instance of Portkey or a
> specific enterprise endpoint.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.