class RubyLLM::Protocol

A Protocol knows how to talk to a family of provider APIs: rendering request payloads, parsing responses, streaming chunks, and naming the endpoints involved. Its counterpart, Provider, knows where to talk and who it is. The protocols that ship with the gem live under RubyLLM::Protocols.

Subclass Protocol, or a shipped subclass such as RubyLLM::Protocols::ChatCompletions, to support a new wire format. Each operation (chat, embeddings, moderation, image generation, speech, transcription, and model listing) is served by three kinds of seam method you override:

Override the seams for the operations you support; the rest raise NotImplementedError. For example:

class ChatCompletions < RubyLLM::Protocols::ChatCompletions
  def completion_url
    'v2/chat'
  end
end

A protocol instance is constructed by its Provider and borrows the provider’s Connection, so subclasses never build HTTP clients themselves.