OpenAICompatibleDialect

org.llm4s.llmconnect.provider.OpenAICompatibleDialect
See theOpenAICompatibleDialect companion object

The places where an OpenAI-compatible provider departs from the plain /chat/completions wire format.

OpenAICompatibleClient holds everything the providers share - request building, the HTTP round trip, SSE streaming, tool-call fan-out, error mapping, exchange logging - written once. A dialect answers the handful of questions on which they differ, and every answer defaults to the standard format, so a provider overrides only where it departs from it:

The generic openai-compatible provider uses OpenAICompatibleDialect.standard, which overrides nothing but headers. DeepSeek, Z.ai and OpenRouter each override two to five members. A new OpenAI-compatible provider whose differences fit these members is a dialect and a descriptor, not a client; one whose differences do not should extend this trait rather than fork OpenAICompatibleClient (#1132).

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def addReasoning(body: Obj, model: String, options: CompletionOptions): Unit

Adds provider-specific reasoning fields to a request body, given the configured model and the caller's options. Standard: adds nothing, so CompletionOptions.reasoning is ignored.

Adds provider-specific reasoning fields to a request body, given the configured model and the caller's options. Standard: adds nothing, so CompletionOptions.reasoning is ignored.

Attributes

Whether an assistant message with no text still carries a content field ("" for empty text, null for none). Standard: false - the field is omitted, which is what most providers expect alongside tool_calls.

Whether an assistant message with no text still carries a content field ("" for empty text, null for none). Standard: false - the field is omitted, which is what most providers expect alongside tool_calls.

Attributes

def decodeContent(content: Value): Option[String]

Reads the text of a reply's content value - on a completion's message or a stream's delta. Standard: a JSON string, anything else is no text.

Reads the text of a reply's content value - on a completion's message or a stream's delta. Standard: a JSON string, anything else is no text.

Attributes

def encodeContent(text: String): Value

Encodes the text of a user, system, assistant or tool message. Standard: a JSON string.

Encodes the text of a user, system, assistant or tool message. Standard: a JSON string.

Attributes

def headers: Seq[(String, String)]

Headers sent on every request, after Content-Type and - when the provider has an API key - Authorization: Bearer <key>.

Headers sent on every request, after Content-Type and - when the provider has an API key - Authorization: Bearer <key>.

Attributes

def parseToolCalls(toolCalls: Value): Seq[ToolCall]

Parses the tool_calls array of a non-streaming reply.

Parses the tool_calls array of a non-streaming reply.

Standard: OpenAICompatibleDialect.lenientToolCalls, which fills in missing fields and turns unparseable arguments into {}. Streamed tool calls always go through StreamingToolArgumentParser, which keeps unparseable arguments as a raw string.

Attributes

def reasoningTokens(usage: Value): Option[Int]

Reads the reasoning-token count from a usage object. Standard: none.

Reads the reasoning-token count from a usage object. Standard: none.

Attributes

def thinking(obj: Value): Option[String]

Reads the model's thinking from a JSON object: a completion's message (then, if that has none, its enclosing choice), or a stream's delta. Standard: none.

Reads the model's thinking from a JSON object: a completion's message (then, if that has none, its enclosing choice), or a stream's delta. Standard: none.

Attributes