openai-generic
The openai-generic
provider supports all APIs that use OpenAI’s request and
response formats, such as Groq, HuggingFace, Ollama, OpenRouter, and Together AI.
Example:
Non-forwarded options
The base URL for the API.
Default: https://api.openai.com/v1
The default role for any prompts that don’t specify a role.
We don’t do any validation of this field, so you can pass any string you wish.
Default: system
Will be used to build the Authorization
header, like so: Authorization: Bearer $api_key
If api_key
is not set, or is set to an empty string, the Authorization
header will not be sent.
Default: <none>
Additional headers to send with the request.
Example:
The role to use if the role is not in the allowed_roles. Default: "user"
usually, but some models like OpenAI’s gpt-4o
will use "system"
Picked the first role in allowed_roles
if not “user”, otherwise “user”.
Which roles should we forward to the API? Default: ["system", "user", "assistant"]
usually, but some models like OpenAI’s o1-mini
will use ["user", "assistant"]
When building prompts, any role not in this list will be set to the default_role
.
Which role metadata should we forward to the API? Default: []
For example you can set this to ["foo", "bar"]
to forward the cache policy to the API.
If you do not set allowed_role_metadata
, we will not forward any role metadata to the API even if it is set in the prompt.
Then in your prompt you can use something like:
You can use the playground to see the raw curl request to see what is being sent to the API.
Whether the internal LLM client should use the streaming API. Default: true
Then in your prompt you can use something like:
Forwarded options
BAML will auto construct this field for you from the prompt
BAML will auto construct this field for you based on how you call the client in your code
The model to use.
For OpenAI, this might be "gpt-4o-mini"
; for Ollama, this might be "llama2"
. The exact
syntax will depend on your API provider’s documentation: we’ll just forward it to them as-is.
For all other options, see the official OpenAI API documentation.