MistralClient.Config (mistralex_ai v0.1.0)

View Source

Configuration management for the Mistral AI client.

This module handles configuration from multiple sources:

  1. Application configuration
  2. Environment variables
  3. Runtime options

Configuration Options

  • :api_key - Mistral API key (required)
  • :base_url - Base URL for the API (default: "https://api.mistral.ai")
  • :timeout - Request timeout in milliseconds (default: 30_000)
  • :max_retries - Maximum number of retries (default: 3)
  • :retry_delay - Base delay between retries in milliseconds (default: 1_000)
  • :user_agent - User agent string (default: "mistral-client-elixir/0.1.0")

Configuration Sources

Application Configuration

config :mistralex_ai,
  api_key: "your-api-key",
  base_url: "https://api.mistral.ai",
  timeout: 30_000

Environment Variables

export MISTRAL_API_KEY="your-api-key"
export MISTRAL_BASE_URL="https://api.mistral.ai"
export MISTRAL_TIMEOUT="30000"

Runtime Options

config = MistralClient.Config.new(api_key: "runtime-key")

Summary

Functions

Get the current configuration.

Get the API key from configuration sources.

Get the base URL from configuration sources.

Get the maximum retries from configuration sources.

Get the retry delay from configuration sources.

Get the timeout from configuration sources.

Get the user agent from configuration sources.

Create a new configuration with optional overrides.

Validate the configuration.

Types

t()

@type t() :: %MistralClient.Config{
  api_key: String.t(),
  base_url: String.t(),
  max_retries: integer(),
  retry_delay: integer(),
  timeout: integer(),
  user_agent: String.t()
}

Functions

get()

@spec get() :: t()

Get the current configuration.

Merges configuration from application config and environment variables.

Examples

config = MistralClient.Config.get()
%MistralClient.Config{api_key: "your-key", ...}

get_api_key()

@spec get_api_key() :: String.t() | nil

Get the API key from configuration sources.

Checks in order:

  1. Application configuration
  2. MISTRAL_API_KEY environment variable

Examples

"your-api-key" = MistralClient.Config.get_api_key()

get_base_url()

@spec get_base_url() :: String.t()

Get the base URL from configuration sources.

Examples

"https://api.mistral.ai" = MistralClient.Config.get_base_url()

get_max_retries()

@spec get_max_retries() :: integer()

Get the maximum retries from configuration sources.

Examples

3 = MistralClient.Config.get_max_retries()

get_retry_delay()

@spec get_retry_delay() :: integer()

Get the retry delay from configuration sources.

Examples

1_000 = MistralClient.Config.get_retry_delay()

get_timeout()

@spec get_timeout() :: integer()

Get the timeout from configuration sources.

Examples

30_000 = MistralClient.Config.get_timeout()

get_user_agent()

@spec get_user_agent() :: String.t()

Get the user agent from configuration sources.

Examples

"mistral-client-elixir/0.1.0" = MistralClient.Config.get_user_agent()

new(options \\ [])

@spec new(keyword()) :: t()

Create a new configuration with optional overrides.

Parameters

  • options - Keyword list of configuration options

Examples

config = MistralClient.Config.new(api_key: "custom-key")
config = MistralClient.Config.new(timeout: 60_000, max_retries: 5)

validate(config)

@spec validate(t()) :: :ok | {:error, String.t()}

Validate the configuration.

Returns :ok if valid, or {:error, reason} if invalid.

Examples

:ok = MistralClient.Config.validate(config)
{:error, "API key is required"} = MistralClient.Config.validate(%Config{api_key: nil})