ChatCompletions

constructor(name: String, apiKey: String? = null, httpOptions: HttpOptions? = null)

Creates a ChatCompletions model backed by an OpenAI-compatible Chat Completions endpoint.

Parameters

name

The model name, such as gpt-4o, or google/gemini-3.1-flash-lite on Vertex AI.

apiKey

The API key, sent as a bearer token; a blank one counts as unset. Falls back to OPENAI_API_KEY only when httpOptions sets no base URL, so that key never goes to a base URL the caller sets.

httpOptions

The base URL (OPENAI_BASE_URL, else OpenAI's, when unset), extra headers, and timeout, which bounds each unary attempt and the start of a stream. A stream also fails after 10 minutes without data, or the timeout if longer; a zero or infinite timeout disables both.

Throws

If no key is found and the base URL is unset or blank, or if httpOptions has a negative timeout or any apiVersion.


constructor(name: String, httpOptions: HttpOptions? = null, apiKeyProvider: () -> String)

Creates a ChatCompletions model that calls apiKeyProvider before each request, for a key that expires, such as a Google Cloud access token.

Parameters

name

The model name, such as gpt-4o, or google/gemini-3.1-flash-lite on Vertex AI.

httpOptions

The base URL (OPENAI_BASE_URL, else OpenAI's, when unset), extra headers, and timeout, which bounds each unary attempt and the start of a stream. A stream also fails after 10 minutes without data, or the timeout if longer; a zero or infinite timeout disables both.

apiKeyProvider

Returns the API key, sent as a bearer token.

Throws

If httpOptions has a negative timeout or any apiVersion.