# `Codex.Thread`
[🔗](https://github.com/nshkrdotcom/codex_sdk/blob/v0.18.0/lib/codex/thread.ex#L1)

Represents a Codex conversation thread and exposes turn execution APIs.

# `t`

```elixir
@type t() :: %Codex.Thread{
  codex_opts: Codex.Options.t(),
  continuation_token: String.t() | nil,
  labels: map(),
  metadata: map(),
  pending_tool_failures: [map()],
  pending_tool_outputs: [map()],
  rate_limits: Codex.Protocol.RateLimit.Snapshot.t() | map() | nil,
  resume: :last | nil,
  thread_id: String.t() | nil,
  thread_opts: Codex.Thread.Options.t(),
  transport: :exec | {:app_server, pid()},
  transport_ref: reference() | nil,
  usage: map()
}
```

# `user_input`

```elixir
@type user_input() :: String.t() | [user_input_block()]
```

# `user_input_block`

```elixir
@type user_input_block() :: map()
```

# `rate_limits`

```elixir
@spec rate_limits(t()) :: Codex.Protocol.RateLimit.Snapshot.t() | map() | nil
```

Returns the most recent account rate limit snapshot for this thread, if any.

# `run`

```elixir
@spec run(t(), user_input(), map() | keyword()) ::
  {:ok, Codex.Turn.Result.t()} | {:error, term()}
```

Executes a blocking multi-turn run using the agent runner.

# `run_auto`

```elixir
@spec run_auto(t(), String.t(), keyword()) ::
  {:ok, Codex.Turn.Result.t()} | {:error, term()}
```

Executes an auto-run loop, retrying while a continuation token is present.

Options:
  * `:max_attempts` – maximum number of attempts (default: 3)
  * `:backoff` – unary function invoked with current attempt (default: exponential sleep)
  * `:turn_opts` – per-turn options forwarded to each attempt

# `run_streamed`

```elixir
@spec run_streamed(t(), user_input(), map() | keyword()) ::
  {:ok, Codex.RunResultStreaming.t()} | {:error, term()}
```

Executes a run and returns a stream of events for progressive consumption.

The stream is lazy; events will not be produced until enumerated.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
