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:
-
render_*serializes aRubyLLMrequest into the wire payload, such asrender_payloadfor chat orrender_embedding_payload. -
*_urlnames the endpoint, such ascompletion_urlorembedding_url. -
parse_*turns the wire response back intoRubyLLMobjects, such asparse_completion_bodyorparse_embedding_response.
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.
Attributes
The provider’s Configuration.
The provider’s HTTP connection. Subclasses use it to reach their endpoints.
The Provider this protocol talks through.