# OpenAI

> Run Everruns agents on OpenAI models via the Responses API or Chat Completions, including Azure OpenAI and any OpenAI-compatible endpoint.

Source: <https://everruns.com/docs/providers/openai/>

Everruns runs agents on [OpenAI](https://openai.com/) models through a uniform driver, mapping its provider-neutral messages, tools, and reasoning onto the OpenAI wire format. The same driver also powers any **OpenAI-compatible endpoint** through a custom base URL. For Azure deployments, use the dedicated [Azure OpenAI](https://everruns.com/docs/providers/azure-openai/) provider instead.

## What you get

* **Responses API** (recommended), the default driver, with stateful continuation and server-side context compaction on `api.openai.com` and Azure OpenAI hosts.
* **Chat Completions**: a compatibility driver (`openai_completions`) for legacy integrations and OpenAI-compatible gateways.
* **Streaming, tool calls, and reasoning** mapped to provider-neutral Everruns types, including extended thinking on reasoning models.
* **Prompt caching** via a deterministic cache key derived from stable request inputs.
* **Structured output**: a direct model call can require a reply that matches a JSON Schema, enforced by OpenAI (`text.format` on the Responses API, `response_format` on Chat Completions).
* **Background mode** for `xhigh` and `max` reasoning on OpenAI and Azure: the response keeps running at OpenAI if the connection drops or the worker running the turn restarts, and Everruns picks the stream back up instead of paying for the call twice. A cancelled turn cancels the response. Background mode stores the response, so organizations with zero data retention fall back to a normal streaming call.
* **WebSocket transport (opt-in)**: on `api.openai.com`, a call can stream over OpenAI’s Responses WebSocket mode instead of HTTP streaming, keeping one connection open across the turns of a tool loop. OpenAI recommends it for the `ultrafast` speed tier. It is off by default; see [WebSocket transport](#websocket-transport).

## Configure in Everruns

1. Go to **Settings** → **Providers** and click **Add provider**.
2. Choose **OpenAI** (Responses API) for new setups, or **OpenAI Completions** for Chat Completions compatibility. For Azure, choose the dedicated [Azure OpenAI](https://everruns.com/docs/providers/azure-openai/) provider instead.
3. Paste your OpenAI API key. Get one from the [OpenAI API keys page](https://platform.openai.com/api-keys).
4. (Optional) Set a **base URL** to target another OpenAI-compatible endpoint.
5. Save. Everruns discovers available models automatically.

## OpenAI-compatible endpoints

The OpenAI driver works with any OpenAI-compatible API. Set the **base URL** to your endpoint. Self-hosted and proxy gateways are treated as stateless, so the driver replays the full transcript each turn instead of relying on server-side continuation. For Microsoft Azure deployments, use the dedicated [Azure OpenAI](https://everruns.com/docs/providers/azure-openai/) provider, which is recognized as a stateful host.

## WebSocket transport

HTTP streaming (SSE) is the default. To use OpenAI’s [WebSocket mode](https://developers.openai.com/api/docs/guides/websocket-mode) instead, opt in per call with the `openai/websocket` driver option set to `true` (`false` opts a call out), or for a whole provider when you build it in code:

```rust
use everruns_drivers::openai::OpenAIChatDriver;


let driver = OpenAIChatDriver::new().with_websocket_transport(true);
```

Each turn of a tool loop continues on the connection the previous turn used, sending only the new tool results. The transport applies to `api.openai.com` only; Azure OpenAI and custom endpoints keep using HTTP streaming. If the socket cannot connect, or drops or reports an error before the response starts, the call is sent over HTTP streaming instead, so opting in never fails a call that HTTP would have served. Background-mode calls always use HTTP.

## Models

Models are discovered when the provider is created and on each sync. OpenAI’s `/models` listing carries only identifiers, so capability and cost metadata come from Everruns’ built-in model profiles, matched by model id.

## Links

* [OpenAI Platform](https://platform.openai.com/)
* [`everruns-drivers` on crates.io](https://crates.io/crates/everruns-drivers), feature `openai`
* [Migrate between providers](https://everruns.com/docs/how-to/migrate-providers/)