struct

AI::OpenAI::OpenAIConfig

Inherits Struct < Value < Object

Configuration for OpenAI API models.

This struct holds the configuration needed to make API calls to OpenAI or OpenAI-compatible providers.

Constructors

new(provider : String, url : Proc(URLOptions, String), headers : Proc(Hash(String, String)), generate_id : Proc(String) | Nil = nil, file_id_prefixes : Array(String) | Nil = nil)
Source

Instance methods

file_id_prefixes

File ID prefixes used to identify file IDs in Responses API.

When nil, all file data is treated as base64 content.

Examples:

  • OpenAI: ["file-"] for IDs like "file-abc123"
  • Azure OpenAI: ["assistant-"] for IDs like "assistant-abc123"
Source
generate_id

Optional proc that generates unique IDs.

Used for generating tool call IDs and other identifiers.

Source
headers

Proc that returns the headers for API requests.

This is called for each request, allowing for dynamic header generation (e.g., token refresh).

Source
provider

The provider identifier (e.g., "openai.chat", "openai.responses").

Source
url

Proc that builds the full URL for an API endpoint.

Receives a NamedTuple with:

  • model_id: The model identifier
  • path: The API endpoint path (e.g., "/chat/completions")

Returns the complete URL string.

Source