struct AI::OpenAI::OpenAIConfig

Overview

Configuration for OpenAI API models.

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

Defined in:

ai/openai/openai_config.cr

Constructors

Instance Method Summary

Constructor Detail

def self.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) #

[View source]

Instance Method Detail

def file_id_prefixes : Array(String) | Nil #

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"

[View source]
def generate_id : Proc(String) | Nil #

Optional proc that generates unique IDs.

Used for generating tool call IDs and other identifiers.


[View source]
def headers : Proc(Hash(String, String)) #

Proc that returns the headers for API requests.

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


[View source]
def provider : String #

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


[View source]
def url : Proc(URLOptions, String) #

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.


[View source]