Sycophant.Config (sycophant v0.4.2)

Copy Markdown

Centralized configuration for Sycophant with schema validation.

Configuration is read from the :sycophant application environment and validated through Zoi schemas.

Provider Credentials

# config/runtime.exs
config :sycophant, :providers,
  openai: [api_key: System.get_env("OPENAI_API_KEY")],
  anthropic: [api_key: System.get_env("ANTHROPIC_API_KEY")],
  amazon_bedrock: [
    access_key_id: System.get_env("AWS_ACCESS_KEY_ID"),
    secret_access_key: System.get_env("AWS_SECRET_ACCESS_KEY"),
    region: "us-east-1"
  ],
  azure: [
    api_key: System.get_env("AZURE_API_KEY"),
    base_url: "https://my-resource.openai.azure.com",
    deployment_name: "gpt-4o",
    api_version: "2025-04-01-preview"
  ]

Tesla HTTP Client

config :sycophant, :tesla,
  adapter: Tesla.Adapter.Mint,
  middlewares: [Tesla.Middleware.Logger]

Summary

Functions

Fetches and validates the configuration for the given provider name.

Fetches and validates the Tesla HTTP client configuration.

Returns the wire protocol defaults map from application config.

Functions

provider(name)

@spec provider(atom()) ::
  {:ok, Sycophant.Config.Provider.t()} | {:error, [Zoi.Error.t()]}

Fetches and validates the configuration for the given provider name.

Reads the :providers key from the :sycophant application environment, extracts the entry matching name, and parses it through the Provider Zoi schema.

Examples

Application.put_env(:sycophant, :providers, openai: [api_key: "sk-test"])
{:ok, config} = Sycophant.Config.provider(:openai)
config.api_key
#=> "sk-test"

tesla()

@spec tesla() :: {:ok, Sycophant.Config.Tesla.t()} | {:error, [Zoi.Error.t()]}

Fetches and validates the Tesla HTTP client configuration.

Reads the :tesla key from the :sycophant application environment and parses it through the Tesla Zoi schema. The returned struct contains the adapter module and any additional middlewares to inject into every request.

Examples

Application.put_env(:sycophant, :tesla, adapter: Tesla.Adapter.Mint)
{:ok, config} = Sycophant.Config.tesla()
config.adapter
#=> Tesla.Adapter.Mint

wire_protocol_defaults()

@spec wire_protocol_defaults() :: map()

Returns the wire protocol defaults map from application config.

Used by ModelResolver to fall back to a configured wire protocol when LLMDB metadata doesn't specify one for a provider. Each provider maps to a nested map keyed by kind (:chat, :embedding, etc.).