starflow/api_key

Types

Represents an API key associated with a specific provider. This type ensures that API keys are always paired with their corresponding provider, preventing misuse of keys across different services.

Fields

  • provider: The provider this API key is for (e.g., Anthropic)
  • String: The actual API key value

Examples

// Create an Anthropic API key
let key = new(providers.Anthropic, "sk-ant-123...")

// Pattern match if needed
case key {
  APIKey(providers.Anthropic, value) -> // Handle Anthropic key
  APIKey(other_provider, _) -> // Handle other provider
}
pub type APIKey {
  APIKey(provider: providers.Provider, String)
}

Constructors

  • APIKey(provider: providers.Provider, String)

Functions

pub fn get(api_key: APIKey) -> String

Retrieves the raw API key string from an APIKey. This is typically used when making API requests where the raw key is needed for authentication.

Examples

let key = new(providers.Anthropic, "sk-ant-123...")
let raw_key = get(key)  // Returns "sk-ant-123..."

// Common usage in request headers
request.set_header("x-api-key", get(key))
pub fn new(provider: Provider, key: String) -> APIKey

Creates a new APIKey with the specified provider and key value.

Arguments

  • provider: The provider this key is associated with
  • key: The API key string

Examples

// Using environment variable
use key <- result.try(
  envoy.get("ANTHROPIC_API_KEY")
  |> result.map(new(providers.Anthropic, _))
)

// Direct initialization
let key = new(providers.Anthropic, "sk-ant-123...")
Search Document