View Source Anthropic.HttpClient.Utils (anthropic_community v0.4.3)
Provides utility functions for constructing HTTP requests for use with the Finch HTTP client. This module facilitates the assembly of request paths and headers based on configuration options, specifically tailored for interacting with the Anthropic API.
Summary
Functions
Constructs the headers for an HTTP request based on the provided Anthropic.Config
struct.
Builds the complete request URL from a base API URL and a specific path.
Functions
Constructs the headers for an HTTP request based on the provided Anthropic.Config
struct.
This function generates a list of HTTP headers necessary for making requests to the Anthropic API, including authentication and content type headers.
Parameters
opts
: TheAnthropic.Config
struct containing configuration options like the API key and the API version.
Returns
- A list of tuples where each tuple represents an HTTP header. Includes the API key, Anthropic version, and content type headers.
Examples
iex> Anthropic.HttpClient.Utils.build_header(%Anthropic.Config{api_key: "your_api_key", anthropic_version: "2023-01"})
[
{"x-api-key", "your_api_key"},
{"anthropic-version", "2023-01"},
{"content-type", "application/json"}
]
Builds the complete request URL from a base API URL and a specific path.
This function constructs the full URL by appending the given path to the base API URL. It is designed to ensure that the URL structure is correctly formed for API requests.
Parameters
path
: The specific API endpoint path to be appended to the base URL.api_url
: The base URL of the API.
Returns
- A string representing the complete URL for the API request.
Examples
iex> Anthropic.HTTPClient.Utils.build_path("/v1/models", "https://api.anthropic.com")
"https://api.anthropic.com/v1/models"