OpenAI

Use OpenAI GPT and reasoning models with Agno agents.

GPT models are used as the default LLM by Agents. OpenAI supports a variety of models. See the full list.

We recommend experimenting to find the best-suited model for your use-case. Here are some general recommendations:

  • gpt-5.4 is good for most general use-cases.
  • gpt-5.4-mini is good for smaller tasks and faster inference.
  • o4-mini and o3 are good for complex reasoning and multi-step tasks.

OpenAI has tier-based rate limits. See the rate limit docs.

Installation

uv pip install -U agno openai

Authentication

Set your OPENAI_API_KEY environment variable. You can get one from OpenAI here.

export OPENAI_API_KEY="YOUR_API_KEY"

Example

Use OpenAIChat with your Agent:

from agno.agent import Agent
from agno.models.openai import OpenAIChat

agent = Agent(
    model=OpenAIChat(id="gpt-5.4-mini"),
    markdown=True
)

# Print the response in the terminal
agent.print_response("Share a 2 sentence horror story.")

Prompt caching

OpenAI applies prompt caching automatically to eligible prompt prefixes. This is separate from Agno's local response cache. Read more about how OpenAI handles caching in their docs.

View more examples here.

Parameters

See the OpenAI Chat Completions reference. The table lists Agno defaults: None generally leaves a setting to the API. Not every model accepts every parameter or value.

ParameterTypeDefaultDescription
idstr"gpt-5.4-mini"The id of the OpenAI model to use
namestr"OpenAIChat"The name of the model
providerstr"OpenAI"The provider of the model
collect_metrics_on_completionboolFalseCollect token metrics only from the final streaming chunk (for providers with cumulative token counts)
storeOptional[bool]NoneStore completion output for use in distillation or evals
reasoning_effortOptional[str]NoneReasoning effort; accepted values depend on the model (for example none, minimal, low, medium, high, xhigh, max)
verbosityOptional[Literal["low", "medium", "high"]]NoneControls verbosity level of reasoning models
metadataOptional[Dict[str, Any]]NoneDeveloper-defined metadata to associate with the completion
frequency_penaltyOptional[float]NonePenalizes new tokens based on their frequency in the text so far (-2.0 to 2.0)
logit_biasOptional[Any]NoneModifies the likelihood of specified tokens appearing in the completion
logprobsOptional[bool]NoneWhether to return log probabilities of the output tokens
top_logprobsOptional[int]NoneNumber of most likely tokens to return log probabilities for (0 to 20)
max_tokensOptional[int]NoneMaximum number of tokens to generate (deprecated, use max_completion_tokens)
max_completion_tokensOptional[int]NoneMaximum number of completion tokens to generate
modalitiesOptional[List[str]]NoneList of modalities to use ("text" and/or "audio")
audioOptional[Dict[str, Any]]NoneAudio configuration (e.g., {"voice": "alloy", "format": "wav"})
presence_penaltyOptional[float]NonePenalizes new tokens based on whether they appear in the text so far (-2.0 to 2.0)
seedOptional[int]NoneBest-effort reproducibility where supported; determinism is not guaranteed
stopOptional[Union[str, List[str]]]NoneUp to 4 sequences where the API will stop generating further tokens
temperatureOptional[float]NoneControls randomness in the model's output (0.0 to 2.0)
userOptional[str]NoneA unique identifier representing your end-user
top_pOptional[float]NoneControls diversity via nucleus sampling (0.0 to 1.0)
service_tierOptional[str]NoneService tier such as auto, default, flex, priority, scale, or fast; availability depends on model and endpoint
strict_outputboolTrueControls schema adherence for structured outputs
extra_headersOptional[Any]NoneAdditional headers to include in requests
extra_queryOptional[Any]NoneAdditional query parameters to include in requests
extra_bodyOptional[Any]NoneAdditional body parameters to include in requests
request_paramsOptional[Dict[str, Any]]NoneAdditional parameters to include in the request
role_mapOptional[Dict[str, str]]NoneMapping of message roles to OpenAI roles
api_keyOptional[str]NoneThe API key for authenticating with OpenAI (defaults to OPENAI_API_KEY env var)
organizationOptional[str]NoneThe organization ID to use for requests
base_urlOptional[Union[str, httpx.URL]]NoneThe base URL for the OpenAI API
timeoutOptional[float]NoneRequest timeout in seconds
max_retriesOptional[int]NoneMaximum number of retries for failed requests
default_headersOptional[Any]NoneDefault headers to include in all requests
default_queryOptional[Any]NoneDefault query parameters to include in all requests
http_clientOptional[Union[httpx.Client, httpx.AsyncClient]]NoneHTTP client instance for making requests
client_paramsOptional[Dict[str, Any]]NoneAdditional parameters for client configuration

OpenAIChat is a subclass of the Model class and has access to the same params.