pub struct ClaudeHttpAdapter { /* private fields */ }Expand description
HTTP adapter that routes to the Anthropic Messages API.
Construction reads CORTEX_CLAUDE_API_KEY from the environment and
validates the model string. The adapter is Send + Sync and may be placed
behind an Arc<dyn LlmAdapter>.
The max_sensitivity field enforces the ADR 0048 §3 data-classification
gate: prompts containing inline high-sensitivity markers are rejected before
any bytes leave the machine when the gate is set below High.
Implementations§
Source§impl ClaudeHttpAdapter
impl ClaudeHttpAdapter
Sourcepub const ANTHROPIC_API_BASE: &'static str = "https://api.anthropic.com"
pub const ANTHROPIC_API_BASE: &'static str = "https://api.anthropic.com"
The base URL for all Anthropic API requests.
Sourcepub const ANTHROPIC_API_KEY_ENV: &'static str = "CORTEX_CLAUDE_API_KEY"
pub const ANTHROPIC_API_KEY_ENV: &'static str = "CORTEX_CLAUDE_API_KEY"
Environment variable that must contain the Anthropic API key.
Construction fails with LlmError::InvalidRequest if this variable
is absent or empty.
Sourcepub const ANTHROPIC_VERSION_HEADER: &'static str = "2023-06-01"
pub const ANTHROPIC_VERSION_HEADER: &'static str = "2023-06-01"
anthropic-version header value required by the Messages API.
Sourcepub fn new(
model: String,
max_sensitivity: Option<MaxSensitivity>,
) -> Result<Self, LlmError>
pub fn new( model: String, max_sensitivity: Option<MaxSensitivity>, ) -> Result<Self, LlmError>
Construct a ClaudeHttpAdapter for model with max_sensitivity.
max_sensitivity controls the data-classification gate (ADR 0048 §3).
Pass None to use the default of MaxSensitivity::Medium, which
blocks high-sensitivity memories from being sent to the remote endpoint.
Returns LlmError::InvalidRequest when:
CORTEX_CLAUDE_API_KEYis absent or empty.modelis empty.modelcontains the string"latest"(forbidden to preserve audit-trail identity; see ADR 0044 §3 and ADR 0048).
Trait Implementations§
Source§impl Clone for ClaudeHttpAdapter
impl Clone for ClaudeHttpAdapter
Source§fn clone(&self) -> ClaudeHttpAdapter
fn clone(&self) -> ClaudeHttpAdapter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ClaudeHttpAdapter
impl Debug for ClaudeHttpAdapter
Source§impl LlmAdapter for ClaudeHttpAdapter
impl LlmAdapter for ClaudeHttpAdapter
Source§fn stream_boxed(&self, req: LlmRequest) -> BoxStream<'_>
fn stream_boxed(&self, req: LlmRequest) -> BoxStream<'_>
Override with true Anthropic SSE streaming via POST /v1/messages with
"stream": true.
Uses ureq (synchronous) inside spawn_blocking. The blocking reader
collects all SSE lines into a Vec before yielding them; the
async_stream::stream! block then emits items one by one.
TODO: replace ureq with an async HTTP client to achieve true
line-by-line streaming without buffering the entire response.
Source§fn adapter_id(&self) -> &'static str
fn adapter_id(&self) -> &'static str
"claude",
"ollama", "replay"). Constants — implementations MUST NOT vary
this per call.Source§fn complete<'life0, 'async_trait>(
&'life0 self,
req: LlmRequest,
) -> Pin<Box<dyn Future<Output = Result<LlmResponse, LlmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn complete<'life0, 'async_trait>(
&'life0 self,
req: LlmRequest,
) -> Pin<Box<dyn Future<Output = Result<LlmResponse, LlmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
req.timeout_ms and returning LlmError::Timeout when exceeded.