Skip to content

pydantic_ai.models.openai_codex

Setup

For details on how to set up authentication with this model, see model configuration for OpenAI Codex.

OpenAICodexModel

Bases: OpenAIResponsesModel

A model that uses the OpenAI Codex backend under a ChatGPT/Codex subscription.

This model mirrors the official Codex client’s prompt-cache affinity by sending the session-id, thread-id, and x-client-request-id headers and the prompt_cache_key field, all derived from the conversation_id of the message history. Explicit extra_headers and openai_prompt_cache_key settings win.

Apart from __init__, all methods are private or match those of the base class.

Methods

__init__
def __init__(
    model_name: OpenAIModelName,
    *,
    provider: Literal['openai-codex'] | Provider[AsyncOpenAI] = 'openai-codex',
    profile: ModelProfileSpec | None = None,
    settings: ModelSettings | None = None,
)

Initialize an OpenAI Codex model.

Parameters

model_name : OpenAIModelName

The name of the OpenAI model to use.

provider : Literal[‘openai-codex’] | Provider[AsyncOpenAI] Default: 'openai-codex'

The provider to use. Defaults to 'openai-codex'.

profile : ModelProfileSpec | None Default: None

The model profile to use. Defaults to a profile picked by the provider based on the model name.

settings : ModelSettings | None Default: None

Default model settings for this model instance.