openai.ChatClient
One model turn against OpenAI's Chat Completions API (`POST https://api.openai.com/v1/chat/completions`).
Signature
class openai.ChatClientOne model turn against OpenAI's Chat Completions API
(POST https://api.openai.com/v1/chat/completions).
The sibling of openai.ResponsesClient: same provider, older and far more
widely-cloned endpoint. Reach for this one when you want chat-completions
semantics from OpenAI itself; for any other OpenAI-compatible server use
openai.GenericClient, openai.OllamaClient, openai.OpenRouterClient or
openai.AzureClient, which are the same wire core with different compat
flags (openai/ns_internal/chat.baml).
Source:<builtin>/openai/chat.bamlbytes 553–6991
Fields
model
stringapi_key
ai.Credential | nullbase_url
ai.Credential | nullrequest_timeout_ms
int | nulltime_to_first_token_timeout_ms
int | nullrequest_body
baml.json.json | nullheaders
map<string, string> | nullquery_params
map<string, string> | nulltemperature
float | nullmax_tokens
int | nullmax_completion_tokens
int | nulltop_p
float | nullstop
string[] | nullseed
int | nullcapture_wire
boolStatic methods
new
(Creates a client. Construction reads no environment variable, so declaring one is always safe; credentials and endpoints resolve when a request is built.
Instance methods
The provider record: everything the shared core needs to know about this
endpoint. Only stream_options distinguishes first-party OpenAI from a
bare compatible server.
The provider record: everything the shared chat core needs to know
about this endpoint.
params
(The per-request parameters handed to the shared chat core.
Parameters
preview: omit the credential, for rendering a request without sending it.
resolved_api_key
(self) -> string | null throws baml.errors.Io | baml.errors.ParseErrorThe request-time credential: the explicit value (a literal, or the value
of the variable an env.NAME ref points at), else the provider's
canonical variable. Null is reported as a configuration error when the
request is built, naming OPENAI_API_KEY.
resolved_base_url
(self) -> string throws baml.errors.Io | baml.errors.ParseErrorThe request-time base URL, or the provider default.
Implementations
ai.Client for openai.ChatClient
Instance methods
id
(self) -> stringinvoke
(render
(Source:<builtin>/openai/chat.bamlbytes 5607–6409
ai.stream.StreamingClient for openai.ChatClient
Instance methods
invoke_stream
(Source:<builtin>/openai/chat.bamlbytes 6415–6989