Retry
Review retry settings and why invalid model IDs cannot reliably exercise the retry path.
This source first needs an explicit portkey_api_key; its environment variable alone is not read by this adapter. It also assumes an invalid model ID triggers the configured retries. Invalid-model responses commonly use terminal 400 or 404 statuses, which Agno does not retry. Do not run this source as a retry test.
"""Example demonstrating how to set up retries with Portkey."""
from agno.agent import Agent
from agno.models.portkey import Portkey
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
# We will use a deliberately wrong model ID, to trigger retries.
wrong_model_id = "portkey-wrong-id"
agent = Agent(
model=Portkey(
id=wrong_model_id,
retries=3, # Number of times to retry the request.
delay_between_retries=1, # Delay between retries in seconds.
exponential_backoff=True, # If True, the delay between retries is doubled each time.
),
)
agent.print_response("What is the capital of France?")
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
passCurrent Alternative
Follow the basic example's setup to install dependencies and set PORTKEY_API_KEY and your account-owned PORTKEY_MODEL_ID. Save this complete program as portkey_retry.py and run python portkey_retry.py.
These settings control Agno retries. SDK and gateway retry policies are separate and can multiply attempts. A successful request does not test retries; use a controlled transient failure when checking the retry path.
from os import environ
from agno.agent import Agent
from agno.models.portkey import Portkey
agent = Agent(
model=Portkey(
id=environ["PORTKEY_MODEL_ID"],
portkey_api_key=environ["PORTKEY_API_KEY"],
max_retries=0,
retries=3,
delay_between_retries=1,
exponential_backoff=True,
)
)
agent.print_response("What is the capital of France?")Full source: cookbook/90_models/portkey/retry.py