Base error struct for Codex failures.
Error Kinds
:rate_limit- API rate limit exceeded:sandbox_assessment_failed- Sandbox assessment failed:unknown- Unclassified error
Rate Limit Handling
Rate limit errors may include a retry_after_ms hint extracted from
the API response. Use retry_after_ms/1 to access this value.
Summary
Functions
Normalizes raw error payloads into %Codex.Error{} structs.
Creates a rate limit error with optional retry-after hint.
Checks if error is a rate limit error.
Creates a realtime audio error.
Creates a realtime connection closed error.
Creates a realtime connection failed error.
Creates a realtime guardrail tripped error.
Creates a realtime handoff error.
Creates a realtime session error.
Creates a realtime tool error.
Extracts retry-after hint from error if present.
Creates a voice pipeline error.
Creates a voice STT connection error.
Creates a voice STT (speech-to-text) error.
Creates a voice TTS (text-to-speech) error.
Creates a voice workflow error.
Types
@type kind() ::
:rate_limit
| :sandbox_assessment_failed
| :unknown
| :realtime_connection_failed
| :realtime_connection_closed
| :realtime_session_error
| :realtime_audio_error
| :realtime_tool_error
| :realtime_handoff_error
| :realtime_guardrail_tripped
| :voice_stt_error
| :voice_stt_connection_error
| :voice_tts_error
| :voice_workflow_error
| :voice_pipeline_error
| :unsupported_feature
@type t() :: %Codex.Error{ __exception__: true, details: map(), kind: kind(), message: String.t(), retry_after_ms: non_neg_integer() | nil }
Functions
Normalizes raw error payloads into %Codex.Error{} structs.
Accepts maps emitted by codex-rs (turn.failed), basic strings, or already
constructed %Codex.Error{} structs. Known codes and types are classified
into stable :kind atoms so callers can branch on error domains (e.g.,
rate limits, sandbox assessment failures).
Creates a rate limit error with optional retry-after hint.
Options
:retry_after_ms- Suggested delay before retry in milliseconds:details- Additional error details map
Examples
iex> error = Codex.Error.rate_limit("Rate limit exceeded", retry_after_ms: 30_000)
iex> error.kind
:rate_limit
iex> error.retry_after_ms
30_000
Checks if error is a rate limit error.
Examples
iex> error = Codex.Error.rate_limit("Rate limited")
iex> Codex.Error.rate_limit?(error)
true
iex> Codex.Error.rate_limit?(%Codex.Error{kind: :unknown, message: "Other"})
false
Creates a realtime audio error.
Creates a realtime connection closed error.
Creates a realtime connection failed error.
Creates a realtime guardrail tripped error.
Creates a realtime handoff error.
Creates a realtime session error.
Creates a realtime tool error.
@spec retry_after_ms(t()) :: non_neg_integer() | nil
Extracts retry-after hint from error if present.
Returns the delay in milliseconds, or nil if not available.
Examples
iex> error = Codex.Error.rate_limit("Rate limited", retry_after_ms: 60_000)
iex> Codex.Error.retry_after_ms(error)
60_000
iex> Codex.Error.retry_after_ms(%Codex.Error{kind: :unknown, message: "Other"})
nil
Creates a voice pipeline error.
Creates a voice STT connection error.
Creates a voice STT (speech-to-text) error.
Creates a voice TTS (text-to-speech) error.
Creates a voice workflow error.