Basic Agent

Run a Portkey agent in sync, async, and streaming modes.

Create a provider integration in your Portkey Model Catalog, then copy an allowed model string in the form @provider_slug/model_name. Replace @your-provider-slug/gpt-5-nano in the example with that value. The slug is specific to your workspace. These catalog examples need PORTKEY_API_KEY; they do not require a separate virtual key. Pass the key explicitly as portkey_api_key, because the Agno adapter does not read that environment variable automatically.

Code

import asyncio
import os

from agno.agent import Agent, RunOutput  # noqa
from agno.models.portkey import Portkey

# Create model using Portkey
model = Portkey(
    id="@your-provider-slug/gpt-5-nano",
    portkey_api_key=os.getenv("PORTKEY_API_KEY"),
)

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

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Set your Portkey API key

export PORTKEY_API_KEY=***

Install dependencies

uv pip install -U portkey-ai openai agno

Run Agent

Save the code above as basic.py, then run:

python basic.py