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)),
    prompt_caching: Bool,
  )
}

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)),
      prompt_caching: Bool,
    )

    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

    How long to wait for a response, in milliseconds: for the whole response of a non-streaming request, and for each next event of a streaming one.

    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

    Extra top-level request fields for provider-specific options glean has no setting for, such as DeepSeek’s thinking, Qwen’s enable_thinking or Claude’s service_tier. Each one replaces glean’s own field of the same name.

    prompt_caching

    Claude only: cache the prompt, so that a request that starts with the same tools, system prompt and messages as an earlier one reads them from the cache at a fraction of the price. Other providers cache on their own.

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. It replaces glean’s own field of the same name, and 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 prompt_caching(
  config: ProviderConfig,
  enabled: Bool,
) -> ProviderConfig

Cache the prompt (Claude only; see ProviderConfig.prompt_caching). Usage.cache_read_tokens and cache_write_tokens show what it did.

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 how long to wait for a response, in milliseconds (default: 10 minutes, because a model that thinks can take minutes to answer). For a streaming request this is the longest wait for the next event, not for the whole response. A request that times out is tried again like any other failed request, up to max_retries times.

✨ Search Document