Code
cookbook/90_models/portkey/basic.py
import asyncio
from agno.agent import Agent, RunOutput # noqa
from agno.models.portkey import Portkey
# Create model using Portkey
model = Portkey(
id="@first-integrati-707071/gpt-5-nano",
)
agent = Agent(model=model, markdown=True)
# Get the response in a variable
# run: RunOutput = agent.run("What is Portkey and why would I use it as an AI gateway?")
# print(run.content)
if __name__ == "__main__":
# --- Sync ---
agent.print_response("What is Portkey and why would I use it as an AI gateway?")
# --- Sync + Streaming ---
agent.print_response(
"What is Portkey and why would I use it as an AI gateway?", stream=True
)
# --- Async ---
asyncio.run(
agent.aprint_response(
"What is Portkey and why would I use it as an AI gateway?"
)
)
# --- Async + Streaming ---
asyncio.run(
agent.aprint_response("Share a breakfast recipe.", markdown=True, stream=True)
)
Usage
1
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2
Set your API keys
export PORTKEY_API_KEY=***
export PORTKEY_VIRTUAL_KEY=***
3
Install dependencies
uv pip install -U portkey-ai openai agno
4
Run Agent
python cookbook/90_models/portkey/basic.py