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.
export PORTKEY_API_KEY=***
export PORTKEY_VIRTUAL_KEY=***

Example

Use Portkey with your Agent:
from agno.agent import Agent, RunResponse
from agno.models.portkey import Portkey

agent = Agent(
    model=Portkey(id="gpt-4o-mini"),
    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:
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-4o-mini",
        config=config,
    ),
)
View more examples here.

Params

ParameterTypeDefaultDescription
idstr"gpt-4o-mini"The id of the model to use through Portkey
namestr"Portkey"The name of the model
providerstr"Portkey"The provider of the model
portkey_api_keyOptional[str]NoneThe Portkey API key for authentication
virtual_keyOptional[str]NoneThe virtual key for model routing in Portkey
configOptional[Dict[str, Any]]NonePortkey configuration for routing, retries, and policies
base_urlstrPORTKEY_GATEWAY_URLThe Portkey gateway URL
Portkey also supports the params of OpenAI.