gleamstral/client

Types

Client for interacting with the Mistral AI API

Contains the API key required for authentication

pub type Client {
  Client(api_key: String)
}

Constructors

  • Client(api_key: String)

Represents possible errors that can occur when interacting with the Mistral AI API

  • RateLimitExceeded: Returned when API rate limits have been reached
  • Unauthorized: Returned when API key is invalid or missing
  • Unknown: Returned for any other error, with the error message as a string
pub type Error {
  RateLimitExceeded
  Unauthorized
  Unknown(String)
}

Constructors

  • RateLimitExceeded
  • Unauthorized
  • Unknown(String)

Values

pub const api_endpoint: String
pub fn error_decoder() -> Decoder(Error)
pub fn handle_response(
  response: Response(String),
  using decoder: Decoder(a),
) -> Result(a, Error)

Handle HTTP responses from the Mistral AI API

Takes a response and a decoder, and returns either the decoded response or an appropriate error.

The generic type parameters allow this function to work with different request and response types.

pub fn new(api_key: String) -> Client

Creates a new Mistral AI client with the provided API key and HTTP client

Example

// Using gleam_httpc
import gleam_httpc
let client = client.new("your-api-key-here", httpc.send)

// Or using another HTTP client, like gleam_hackney
import hackney
let client = client.new("your-api-key-here", hackney.send)
Search Document