Provider for OpenAI's Responses API.
Normalizes OpenAI's response output items (assistant messages + function calls) to Alloy's content-block format.
Config
Required:
:api_key- OpenAI API key:model- Model name (e.g., "gpt-5.4", "gpt-5.1", "o3-pro")
Optional:
:max_tokens- Max output tokens (default: 4096):system_prompt- System prompt string:api_url- Base URL (default: "https://api.openai.com"). Can point to compatible Responses APIs such as xAI's "https://api.x.ai":provider_state- opaque provider-owned state carried across turns. For Responses APIs Alloy uses%{response_id: "..."}:store- Persist the response server-side when supported:include- Additional response fields to include:tool_choice- Provider-native tool selection mode:parallel_tool_calls- Whether the provider may issue tool calls in parallel:previous_response_id- Explicit Responses continuation ID. Overridesprovider_state.response_idwhen both are present:built_in_tools- provider-native tool definitions to append to custom function tools:web_search-trueor a config map to append aweb_searchtool:x_search-trueor a config map to append anx_searchtool:req_options- Additional options passed to Req
In stateless mode (store not true with no previous response ID), Alloy
automatically requests encrypted reasoning content and round-trips opaque
reasoning output items between tool calls.
Example
Alloy.run("Summarize this code.",
provider: {Alloy.Provider.OpenAI,
api_key: System.get_env("OPENAI_API_KEY"),
model: "gpt-5.4"
}
)
Alloy.run("Review this repo",
provider: {Alloy.Provider.OpenAI,
api_key: System.get_env("XAI_API_KEY"),
api_url: "https://api.x.ai",
model: "grok-4"
}
)
Summary
Types
@type config() :: %{ :api_key => String.t(), :model => String.t(), optional(:max_tokens) => pos_integer(), optional(:system_prompt) => String.t(), optional(:api_url) => String.t(), optional(:provider_state) => map(), optional(:store) => boolean(), optional(:include) => [String.t()], optional(:tool_choice) => String.t() | map(), optional(:parallel_tool_calls) => boolean(), optional(:previous_response_id) => String.t(), optional(:built_in_tools) => [map()], optional(:web_search) => boolean() | map(), optional(:x_search) => boolean() | map(), optional(:req_options) => keyword() }
Configuration for the OpenAI provider. See the module doc for field semantics.