glean/providers/anthropic
Anthropic provider (Claude models), using the Messages API.
Thinking blocks (including redacted ones) are decoded with their signatures and sent back unchanged on the next turn, which Claude requires when thinking and tool use are combined.
Current Claude models don’t return the text of their thinking unless
asked: set include_reasoning (the model builder’s show_reasoning)
to get a summary of it as reasoning content and ReasoningDelta
events. Setting it, or a reasoning_effort, also sends
thinking: {"type": "adaptive"}, which Claude Opus 4.7 and 4.8 need
before they think at all.
Values
pub fn decode_response(
model_id: String,
body: String,
) -> Result(provider.GenerateResult, error.GleanError)
Decode a non-streaming Messages API response body. Public for tests.
pub fn default_config(
api_key api_key: String,
model model: String,
) -> config.ProviderConfig
The default configuration for this provider. Change it with the
glean/providers/config setters, then pass it to from_config.
pub fn encode_request(
config: config.ProviderConfig,
gen_request: provider.GenerateRequest,
stream: Bool,
) -> Result(String, error.GleanError)
Encode a Messages API request body. Fails with ConfigError for JSON
output without a schema, and for a file Claude has no way to take.
Public for tests.
pub fn from_config(
cfg: config.ProviderConfig,
) -> provider.Provider
Create an Anthropic provider from a full config.
pub fn new(
api_key api_key: String,
model model: String,
) -> provider.Provider
Create an Anthropic provider.
Example
let provider = anthropic.new(api_key: "sk-ant-...", model: "claude-sonnet-5-5")