Agentic.LLM.Provider behaviour
(agentic v0.2.2)
Copy Markdown
Behaviour describing one LLM service provider.
Each provider is a small module that declares which transport it uses, points at a base URL, declares env vars for credentials, and optionally implements catalog and usage fetchers.
Required callbacks
id/0— unique atom identifying this providerlabel/0— human-readable nametransport/0— the transport module to usedefault_base_url/0— base URL for API callsenv_vars/0— env var names in priority orderdefault_models/0— static seed of known modelsrequest_headers/1— extra headers given resolved credentialssupports/0— MapSet of capability atoms
Optional callbacks
fetch_catalog/1— dynamic model discoveryfetch_usage/1— quota / usage endpointclassify_http_error/3— provider-specific error overrides
Summary
Callbacks
@callback classify_http_error(non_neg_integer() | nil, term(), term()) :: {atom(), non_neg_integer() | nil} | :default
@callback default_base_url() :: String.t() | nil
@callback default_models() :: [Agentic.LLM.Model.t()]
@callback env_vars() :: [String.t()]
@callback fetch_catalog(Agentic.LLM.Credentials.t()) :: {:ok, [Agentic.LLM.Model.t()]} | {:error, term()} | :not_supported
@callback fetch_usage(Agentic.LLM.Credentials.t()) :: {:ok, term()} | :not_supported
@callback id() :: atom()
@callback label() :: String.t()
@callback request_headers(Agentic.LLM.Credentials.t()) :: [{String.t(), String.t()}]
@callback transport() :: module()
Functions
@spec chat(provider :: module(), params :: map(), opts :: keyword()) :: {:ok, Agentic.LLM.Transport.request()} | {:error, term()}
Call a provider's chat via its declared transport.
Builds the canonical params, resolves credentials, delegates to the transport for request building and response parsing, and performs the HTTP call.
Streaming variant of chat/3.
Calls the provider with stream: true and invokes on_chunk.(text_delta)
for each text chunk received. Returns the complete {:ok, Response.t()}
at the end, same as chat/3.
The on_chunk callback in opts receives each text delta as a binary.