View Source Anthropic.Messages.Request (anthropic_community v0.3.0)
Defines the structure and functionality for creating and sending requests to the Anthropic API.
This module is responsible for encapsulating the data needed for a request, including model specifications, messages, and various control parameters. It also implements the Jason.Encoder
protocol to ensure that instances of this struct can be serialized to JSON format, which is required for API requests.
Summary
Functions
The structure of a request to the Anthropic API.
Creates a new request struct based on the provided configuration.
Encodes the request to JSON and sends it to the Anthropic API via the Finch HTTP client.
Types
Functions
The structure of a request to the Anthropic API.
Includes all necessary fields for making a request, such as model information, messages to process, and parameters to control the behavior of the API response.
@spec create(Anthropic.Config.t()) :: t()
Creates a new request struct based on the provided configuration.
Initializes a request with the parameters specified in the configuration, setting up default values for the request structure.
Parameters
opts
: The Anthropic.Config struct containing configuration options for the request.
Returns
- A new Anthropic.Messages.Request struct initialized with the provided configuration options.
@spec send_request(t(), Keyword.t() | nil) :: {:error, any()} | {:ok, Finch.Response.t()}
Encodes the request to JSON and sends it to the Anthropic API via the Finch HTTP client.
This function serializes the request struct into JSON, builds the request with the correct headers and path, and sends it using Finch.
Parameters
request
: The Anthropic.Messages.Request struct to send.opts
: Additional options for the Finch request.
Returns
{:ok, response}
on successful request and response parsing.{:error, reason}
if the request fails due to encoding issues or HTTP errors.