> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zeroruntime.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Openai

> Python API reference for the openai llm plugin.

<Card title="Usage guide" icon="book" href="/plugins/llm/openai" horizontal>
  Setup, environment variables, and Python/JavaScript/Go usage examples.
</Card>

## OpenAILLM

OpenAI chat/completions LLM provider with streaming and tool-calling support.

Wraps OpenAI's GPT model families behind the SDK's `LLM` contract. Note the
two parameter regimes: `gpt-5.x` reasoning models are tuned via
`reasoning_effort` and `verbosity`, while `gpt-4.x` non-reasoning models
are tuned via `temperature` and `top_p`.

### Constructor

```python theme={null}
OpenAILLM(*, api_key: 'str | None' = None, model: 'OpenAILLMModel | str' = 'gpt-5.4-nano', temperature: 'float' = 0.7, max_output_tokens: 'int' = 1024, top_p: 'float | None' = None, frequency_penalty: 'float | None' = None, presence_penalty: 'float | None' = None, seed: 'int | None' = None, response_format=None, tool_choice=None, parallel_tool_calls: 'bool | None' = None, stop: 'str | None' = None, user: 'str | None' = None, reasoning_effort: 'str | None' = None, verbosity: 'str | None' = None, streaming: 'bool' = False, wss_url: 'str | None' = None, store: 'bool' = True, **kwargs) -> 'None'
```

<ParamField path="api_key" type="str | None">
  OpenAI API key. Falls back to the `OPENAI_API_KEY` environment variable when omitted.
</ParamField>

<ParamField path="model" type="OpenAILLMModel | str" default="gpt-5.4-nano">
  Model id or `OpenAILLMModel`. Defaults to `'gpt-5.4-nano'`. Use a `gpt-5.x` family model for reasoning workloads or a `gpt-4.x` family model for classic completions.
</ParamField>

<ParamField path="temperature" type="float" default="0.7">
  Sampling temperature (`0`–`2`); higher is more random, lower more deterministic. Defaults to `0.7`. Adjust this or `top_p`, not both. Applies to non-reasoning (`gpt-4.x`) models.
</ParamField>

<ParamField path="max_output_tokens" type="int" default="1024">
  Upper bound on generated tokens, including reasoning tokens for reasoning models. Defaults to `1024`. The legacy `max_completion_tokens` kwarg is accepted and mapped here.
</ParamField>

<ParamField path="top_p" type="float | None">
  Nucleus-sampling probability mass (`0`–`1`); the model considers only the top `top_p` of token probability. Defaults to `None`. Adjust this or `temperature`, not both.
</ParamField>

<ParamField path="frequency_penalty" type="float | None">
  `-2.0`–`2.0`; positive values discourage verbatim repetition. Defaults to `None`.
</ParamField>

<ParamField path="presence_penalty" type="float | None">
  `-2.0`–`2.0`; positive values encourage new topics. Defaults to `None`.
</ParamField>

<ParamField path="seed" type="int | None">
  Best-effort deterministic sampling seed (beta). Defaults to `None`.
</ParamField>

<ParamField path="response_format">
  Output format spec, e.g. `&#123;"type": "json_object"&#125;` or a `json_schema` for Structured Outputs. Defaults to `None` (text).
</ParamField>

<ParamField path="tool_choice">
  Tool-selection control: `"none"`, `"auto"`, `"required"`, or a specific `&#123;"type": "function", ...&#125;` spec. Defaults to `None`.
</ParamField>

<ParamField path="parallel_tool_calls" type="bool | None">
  Whether to allow parallel function calls. Defaults to `None` (provider default of enabled).
</ParamField>

<ParamField path="stop" type="str | None">
  Up to 4 stop sequences at which generation halts. Defaults to `None`.
</ParamField>

<ParamField path="user" type="str | None">
  Stable end-user identifier for abuse monitoring (hash to avoid PII). Defaults to `None`.
</ParamField>

<ParamField path="reasoning_effort" type="str | None">
  Reasoning compute budget for `gpt-5.x` reasoning models. Common values: `'minimal'`, `'low'`, `'medium'`, `'high'` (model-dependent; `'none'` requires `gpt-5.1` or later). Defaults to `None`.
</ParamField>

<ParamField path="verbosity" type="str | None">
  Response verbosity for reasoning models: `'low'`, `'medium'`, or `'high'`. Defaults to `None`.
</ParamField>

<ParamField path="streaming" type="bool" default="False">
  Whether to stream the response incrementally. Defaults to `False`.
</ParamField>

<ParamField path="wss_url" type="str | None">
  Optional WebSocket endpoint override. Defaults to `None`.
</ParamField>

<ParamField path="store" type="bool" default="True">
  Whether OpenAI may store the request/response for later retrieval. Defaults to `True`.
</ParamField>

### aclose

```python theme={null}
def aclose(self) -> 'None'
```

Release any resources held by the provider.

### cancel\_current\_generation

```python theme={null}
def cancel_current_generation(self) -> 'None'
```

Cancel the in-progress generation for the active session, if any.

### chat

```python theme={null}
def chat(self, messages: 'Any', tools: 'Any' = None, conversational_graph: 'Any' = None, **kwargs: 'Any') -> 'AsyncIterator[LLMResponse]'
```

Generate a streamed chat completion.

<ParamField path="messages" type="Any" required>
  The conversation history to send to the model.
</ParamField>

<ParamField path="tools" type="Any">
  Optional tool definitions the model may call.
</ParamField>

<ParamField path="conversational_graph" type="Any">
  Optional conversational graph guiding the exchange.
</ParamField>

<ResponseField name="returns" type="AsyncIterator[LLMResponse]">
  LLMResponse: Response chunks produced as the model generates output.
</ResponseField>

### emit

```python theme={null}
def emit(self, event: 'T', *args: 'Any') -> 'None'
```

Emit an event, invoking all registered handlers with the given arguments.

Handlers are called in registration order. Coroutine handlers are
scheduled on the running event loop. If the emitter is closed, the call
is a no-op.

<ParamField path="event" type="T" required>
  The event to emit.
</ParamField>

### off

```python theme={null}
def off(self, event: 'T', callback: 'Callable[..., Any]') -> 'None'
```

Remove a previously registered handler for an event.

If the handler is not registered for the event, the call is a no-op.

<ParamField path="event" type="T" required>
  The event the handler was registered for.
</ParamField>

<ParamField path="callback" type="Callable[..., Any]" required>
  The handler to remove.
</ParamField>

### on

```python theme={null}
def on(self, event: 'T', callback: 'Callable[..., Any] | None' = None) -> 'Callable[..., Any]'
```

Register a handler for an event.

Can be used directly by passing a callback, or as a decorator when
`callback` is omitted.

<ParamField path="event" type="T" required>
  The event to listen for.
</ParamField>

<ParamField path="callback" type="Callable[..., Any] | None">
  The handler to invoke when the event is emitted. If `None`, a decorator is returned that registers the decorated function.
</ParamField>

<ResponseField name="returns" type="Callable[..., Any]">
  The registered callback when `callback` is provided, otherwise a decorator that registers and returns the function it wraps.
</ResponseField>

***

## OpenAILLMModel

```python theme={null}
OpenAILLMModel = typing.Literal['gpt-5.5', 'gpt-5.4', 'gpt-5.4-mini', 'gpt-5.4-nano', 'gpt-5.4-nano-2026-03-17', 'gpt-5', 'gpt-5-mini', 'gpt-5-nano', 'gpt-5-pro', 'gpt-5-chat-latest', 'gpt-4.1', 'gpt-4.1-mini', 'gpt-4 …
```
