Behaviour for wire format translation between normalized messages and provider APIs.
Each dialect handles encoding requests to provider-specific JSON format and decoding responses/chunks back to normalized LLM structs.
Built-in Dialects
LLM.Dialect.OpenAI- OpenAI Chat Completions (/v1/chat/completions)LLM.Dialect.OpenAIResponse- OpenAI Responses API (/v1/responses)LLM.Dialect.Anthropic- Anthropic Messages API (/v1/messages)LLM.Dialect.Gemini- Gemini API (/v1beta/models/{model}:generateContent)
Summary
Callbacks
Build the request body for the provider API.
Parse a single SSE data line into one or more chunk structs.
Return :done when the stream is complete.
Decode a complete (non-streaming) response into a normalized LLM.Response.
Normalize the thinking option to provider-specific format.
Return extra headers needed for streaming requests.
Return the stream endpoint path (appended to base_url).
Types
@type chunk_type() :: LLM.Stream.Chunk.t() | LLM.Stream.ToolCall.t() | LLM.Stream.Thinking.t() | LLM.Stream.Stop.t() | LLM.Stream.Error.t()
Callbacks
@callback build_request( LLM.Context.t(), keyword() ) :: map()
Build the request body for the provider API.
@callback decode_chunk(String.t()) :: [chunk_type()] | :done
Parse a single SSE data line into one or more chunk structs.
Return :done when the stream is complete.
@callback decode_response(map()) :: {:ok, LLM.Response.t()} | {:error, term()}
Decode a complete (non-streaming) response into a normalized LLM.Response.
Normalize the thinking option to provider-specific format.
Return extra headers needed for streaming requests.
@callback stream_path() :: String.t()
Return the stream endpoint path (appended to base_url).