glean/providers/config

Provider configuration shared by all provider implementations.

Model builders expose this through their configure function, e.g. anthropic.sonnet_5_5(key) |> anthropic.configure(config.timeout(_, 120_000)).

Types

Configuration for creating a provider.

pub type ProviderConfig {
  ProviderConfig(
    api_key: String,
    base_url: String,
    model: String,
    headers: List(#(String, String)),
    timeout_ms: Int,
    max_tokens_field: String,
    max_retries: Int,
    initial_retry_delay_ms: Int,
    send_reasoning_content: Bool,
    stream_usage: Bool,
    extra_body: List(#(String, json.Json)),
  )
}

Constructors

  • ProviderConfig(
      api_key: String,
      base_url: String,
      model: String,
      headers: List(#(String, String)),
      timeout_ms: Int,
      max_tokens_field: String,
      max_retries: Int,
      initial_retry_delay_ms: Int,
      send_reasoning_content: Bool,
      stream_usage: Bool,
      extra_body: List(#(String, json.Json)),
    )

    Arguments

    api_key

    API key for authentication

    base_url

    Base URL for the API (no trailing slash)

    model

    Model ID to use

    headers

    Additional HTTP headers

    timeout_ms

    Request timeout in milliseconds

    max_tokens_field

    Field name for max tokens parameter (e.g. “max_completion_tokens” or “max_tokens”)

    max_retries

    Maximum retries for transient HTTP errors (429, 5xx)

    initial_retry_delay_ms

    Initial retry delay in milliseconds (doubles each retry, with jitter)

    send_reasoning_content

    OpenAI-compatible APIs only: send the model’s earlier reasoning back as reasoning_content (DeepSeek and Kimi require it in tool loops).

    stream_usage

    OpenAI-compatible APIs only: ask for token usage in streaming responses with stream_options.include_usage.

    extra_body

    OpenAI-compatible APIs only: extra top-level request fields for provider-specific options glean has no setting for, such as DeepSeek’s thinking or Qwen’s enable_thinking. They are added after glean’s own fields.

Values

pub fn base_url(
  config: ProviderConfig,
  url: String,
) -> ProviderConfig

Set the base URL.

pub fn extra_body_field(
  config: ProviderConfig,
  name: String,
  value: json.Json,
) -> ProviderConfig

Add an extra top-level request field (OpenAI-compatible providers only). Setting the same name twice keeps the last value.

pub fn headers(
  config: ProviderConfig,
  headers: List(#(String, String)),
) -> ProviderConfig

Add extra headers.

pub fn initial_retry_delay(
  config: ProviderConfig,
  ms: Int,
) -> ProviderConfig

Set initial retry delay in milliseconds (doubles each retry).

pub fn max_retries(
  config: ProviderConfig,
  retries: Int,
) -> ProviderConfig

Set max retries for transient HTTP errors (429, 5xx).

pub fn max_tokens_field(
  config: ProviderConfig,
  field: String,
) -> ProviderConfig

Set the field name used for max tokens in API requests. Defaults to “max_completion_tokens”. Use “max_tokens” for providers that don’t support the newer field name (e.g. Mistral).

pub fn new(
  api_key api_key: String,
  model model: String,
) -> ProviderConfig

Create a config with defaults.

pub fn send_reasoning_content(
  config: ProviderConfig,
  enabled: Bool,
) -> ProviderConfig

Send earlier reasoning back as reasoning_content (OpenAI-compatible providers only).

pub fn stream_usage(
  config: ProviderConfig,
  enabled: Bool,
) -> ProviderConfig

Ask for token usage in streaming responses (OpenAI-compatible providers only).

pub fn timeout(config: ProviderConfig, ms: Int) -> ProviderConfig

Set the request timeout in milliseconds.

✨ Search Document