openai.GenericClient
Any OpenAI-compatible chat-completions endpoint: vLLM, LM Studio, TGI, llama.cpp, Together, Fireworks, a corporate gateway.
Signature
class openai.GenericClientAny OpenAI-compatible chat-completions endpoint: vLLM, LM Studio, TGI, llama.cpp, Together, Fireworks, a corporate gateway.
Two things separate it from openai.ChatClient:
base_urlis REQUIRED. An unset base URL is a configuration error, not a silent fallback to api.openai.com — sending a private prompt to OpenAI because a variable was unset is the worse failure.- all-text messages are sent as
content: "…"rather thancontent: [{"type":"text",…}]. Many compatible servers reject the array form outright; media-bearing messages still use parts. It also sends nostream_options(undocumented outside first-party OpenAI) and requires no credential — a local server usually has none.
Source:<builtin>/openai/generic.bamlbytes 772–6992
Fields
model
stringbase_url
ai.Credential | nullapi_key
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 | 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
compat
(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.ParseErrorNo canonical variable: an unauthenticated request is the normal case for a self-hosted server, so a missing key is not an error here.
resolved_base_url
(Throws ai.errors.InvalidRequest when no base_url resolves. A
base_url = env.NAME naming an UNSET variable resolves to null and lands
here too, so it reports the same clear configuration error rather than a
mystery request to nowhere.
Implementations
ai.Client for openai.GenericClient
Instance methods
id
(self) -> stringinvoke
(render
(Source:<builtin>/openai/generic.bamlbytes 5605–6410
ai.stream.StreamingClient for openai.GenericClient
Instance methods
invoke_stream
(Source:<builtin>/openai/generic.bamlbytes 6416–6990