Skip to main content

Crate klieo_llm_anthropic

Crate klieo_llm_anthropic 

Source
Expand description

Anthropic Messages API client implementing klieo_core::LlmClient.

Wraps Anthropic’s /v1/messages endpoint. Capability declaration (tool_calling, streaming, structured_output, embeddings, max_context_tokens, vision) is computed at construction time from the configured chat-model name; see capabilities::model_capabilities.

Sibling to klieo-llm-ollama and klieo-llm-openai — the three crates implement the same LlmClient trait so a Box<dyn LlmClient> consumer can swap between them without other code changes.

§Differences from OpenAI

  • Auth: x-api-key: <key> header (NOT Authorization: Bearer), plus required anthropic-version: 2023-06-01 header.
  • max_tokens is REQUIRED in every request; the client defaults to 4096 if the caller leaves it unset.
  • Tool input is a JSON object on the wire (not a JSON-encoded string like OpenAI). No string-parse boundary needed.
  • Content blocks are an array of typed blocks (text + tool_use + tool_result), not a flat content: String + parallel tool_calls.
  • Streaming uses TYPED SSE events (event: message_delta etc), not OpenAI’s flat data: lines.
  • Embeddings are NOT supported by Anthropic; embed() returns LlmError::BadRequest.

§Example

use klieo_llm_anthropic::AnthropicClient;
let client = AnthropicClient::new("your-anthropic-api-key", "claude-sonnet-4-6");

§Limitations

  • Vision input is declared in Capabilities::vision but the wire encoding for Image content blocks is not implemented in v0.1.0; see the carryovers section of the implementation plan.
  • Bedrock and Vertex AI deployments are not yet first-class targets; override the base URL via AnthropicClient::with_base_url for now.

Re-exports§

pub use capabilities::model_capabilities;
pub use client::AnthropicClient;

Modules§

capabilities
Static lookup of klieo_core::Capabilities by Anthropic model name.
client
AnthropicClientLlmClient impl over Anthropic’s Messages API.