openai provider supports the OpenAI /chat endpoint with OpenAI-specific default configuration options.
For Azure OpenAI, use the
azure provider instead.For other OpenAI-compatible providers (Groq, Ollama, OpenRouter, Together AI, etc.), use openai-compatible.Quick Start
Authentication
Set your OpenAI API key as an environment variable:Configuration Options
BAML-Specific Options
These options modify the API request sent to OpenAI.Used to build the
Authorization header: Authorization: Bearer $api_keyThe base URL for the OpenAI API. Override this to use different regions or custom endpoints.Example for EU region:
Additional headers to send with requests.
Supported Models
The OpenAI model to use.
You can specify any model name - BAML won’t validate whether it exists.
| Model | Use Case | Context | Key Features |
|---|---|---|---|
| gpt-5 | Coding, agentic tasks, expert reasoning | 400K total | Built-in reasoning, 45% fewer errors |
| gpt-5-mini | Well-defined tasks, cost-efficient | 400K total | Faster alternative to GPT-5 |
| gpt-5-nano | Lightweight tasks, maximum efficiency | 400K total | Most cost-effective GPT-5 variant |
| gpt-4.1 | Large-scale technical work | 1M | Enhanced coding, instruction following |
| gpt-4.1-mini | Balanced performance and cost | 1M | Replaces GPT-4o mini |
| gpt-4.1-nano | Lightweight variant | 1M | Budget-friendly option |
| gpt-4o | General purpose, multimodal | 200K | Updated knowledge cutoff June 2024 |
Model Parameters
These parameters are passed directly to the OpenAI API. Common parameters:temperature- Controls randomness (0-2)max_tokens- Maximum tokens to generatetop_p- Nucleus sampling parameterfrequency_penalty- Reduces repetition (-2.0 to 2.0)presence_penalty- Encourages new topics (-2.0 to 2.0)
Regional Endpoints
To access OpenAI’s API in different regions:Features
- Streaming: Supported for real-time response generation
- Multimodal: Supports text and image inputs
- Function Calling: Native support for tool use and function calling
- JSON Mode: Structured output support
Do Not Set
BAML automatically constructs this from your prompt.
BAML automatically sets this based on how you call the client in your code.