withHeadersProvider

fun withHeadersProvider(name: String, httpOptions: HttpOptions? = null, headersProvider: () -> Map<String, String>): ChatCompletions

Creates a ChatCompletions model that calls headersProvider before each request, for an authorization scheme other than a bearer key, such as a custom header or a signed 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), headers that replace provided ones of the same name, 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.

headersProvider

Returns the headers to send with each request, such as Authorization.

Throws

If httpOptions has a negative timeout or any apiVersion.