starlet/anthropic
Anthropic provider for starlet.
Uses the Anthropic Messages API for chat completions with Claude models.
Usage
import starlet
import starlet/anthropic
let client = anthropic.new(api_key)
starlet.chat(client, "claude-haiku-4-5-20251001")
|> starlet.user("Hello!")
|> starlet.send()
Extended Thinking
For models that support extended thinking, configure a thinking budget:
starlet.chat(client, "claude-haiku-4-5-20251001")
|> anthropic.with_thinking(16384)
|> starlet.max_tokens(32000)
|> starlet.user("Analyze this complex problem...")
|> starlet.send()
Note on max_tokens
Anthropic requires max_tokens in every request. If not explicitly set
via starlet.max_tokens(), a default of 4096 is used.
Values
pub fn new(api_key: String) -> starlet.Client(@internal Ext)
Creates a new Anthropic client with the given API key. Uses the default base URL: https://api.anthropic.com
Note: Anthropic requires max_tokens. If not explicitly set via
starlet.max_tokens(), a default of 4096 is used.
pub fn new_with_base_url(
api_key: String,
base_url: String,
) -> starlet.Client(@internal Ext)
Creates a new Anthropic client with a custom base URL. Useful for proxies or self-hosted endpoints.
Note: Anthropic requires max_tokens. If not explicitly set via
starlet.max_tokens(), a default of 4096 is used.
pub fn thinking(
turn: starlet.Turn(t, f, @internal Ext),
) -> option.Option(String)
Get the thinking content from an Anthropic turn (if present).
pub fn with_thinking(
chat: starlet.Chat(t, f, s, @internal Ext),
budget: Int,
) -> Result(
starlet.Chat(t, f, s, @internal Ext),
starlet.StarletError,
)
Enable extended thinking with a token budget. Budget must be at least 1024 tokens. The upper bound (less than max_tokens) is enforced by the API at request time.