# Class LittleGhost::Providers::OpenAI

Documentation version: Edge

Canonical HTML: https://littleghostai.org/docs/LittleGhost/Providers/OpenAI.html

OpenAI connects LittleGhost features to OpenAI models for generation and
embeddings. Generation uses the Responses API by default and supports
streaming, Tools, and structured results.

    provider = LittleGhost::Providers::OpenAI.new(
      api_key: ENV.fetch("OPENAI_API_KEY"),
      model: ENV.fetch("OPENAI_MODEL")
    )

Supply `api: :chat_completions` only when a model or integration
requires the Chat Completions wire API.

## Inheritance

`LittleGhost::Providers::OpenAI < OpenAICompatible`

## Constants

### `DEFAULT_BASE_URL`

The OpenAI API endpoint used when `base_url` is omitted.

## Class methods

<a id="method-c-new"></a>
### `.new`

```ruby
.new(base_url: DEFAULT_BASE_URL, max_embedding_response_bytes: DEFAULT_MAX_EMBEDDING_RESPONSE_BYTES, **arguments)
```

Uses the official OpenAI API base URL by default.

`max_embedding_response_bytes` bounds the response retained for one embedding
batch. Remaining `arguments` configure the shared generation transport and
retry behavior.

## Instance methods

<a id="method-i-embed"></a>
### `#embed`

```ruby
#embed(request)
```

Embeds one or more strings with the configured OpenAI model.

The optional `:dimensions` request setting selects a supported
output size for models that accept it. The response preserves input order and
raises ProtocolError when OpenAI returns an incomplete or invalid batch.
