Skip to main content

Anthropic

Struct Anthropic 

Source
pub struct Anthropic { /* private fields */ }
Expand description

Calls the Anthropic Messages API.

The key is held here and never journaled — it is transport metadata in exactly the sense a peer credential is, and the same rule applies: a secret in a hash-chained record cannot be redacted afterwards, only discovered.

Implementations§

Source§

impl Anthropic

Source

pub const DEFAULT_TIMEOUT: Duration

Source

pub const VERSION: &'static str = "2023-06-01"

The API version this driver speaks.

Pinned rather than tracking the newest: a provider that changes its response shape under a running plane changes what replay reads back.

Source

pub fn new(key: impl Into<String>) -> Result<Self, ModelError>

A ceiling the request must carry, because the API requires one.

Deliberately not unbounded-by-default: an output limit is the cheapest spend control there is, and the budget ceilings in core::budget govern the run rather than the individual call.

§Errors

If the HTTP client cannot be built.

Source

pub const fn timeout(self, timeout: Duration) -> Self

Bound connection, generation, and response streaming as one operation.

Source

pub fn base(self, base: impl Into<String>) -> Self

Point at a different host — a gateway, or a test server.

Source

pub fn structured_via(self, mode: SchemaMode) -> Self

How to obtain a schema-conforming answer from this model.

Native constrained decoding is gated on particular models. Point this driver at one that predates it and the request is rejected outright — which is loud, but the fix is SchemaMode::ForcedTool, and it is here rather than discovered because the crate cannot ask a model what it supports without a network call on a path that must not make one.

Source

pub fn structured_via_for( self, model: impl Into<String>, mode: SchemaMode, ) -> Self

How to obtain a schema-conforming answer from one model.

Takes precedence over the driver default. This is the knob that matches the shape of the problem: constrained decoding is gated per model, and one driver serves many.

Source

pub fn egress(self, egress: Egress) -> Self

Restrict where this driver may connect.

Deny-by-default once set: a base URL whose host is not granted is refused before the request is built, so nothing leaves and nothing is metered. Unset means no egress control, spelled the same way an absent policy engine is — see Egress.

Source

pub const fn buffered(self) -> Self

Ask for the whole response at once instead of streaming it.

The cost of turning streaming off is stated plainly because it is easy to reach for: a non-streaming response that dies in transit reports Unavailable — cost unknown, treated as safe to repeat, billed as zero. The streaming path reports what it actually burned. Reasons to do it anyway are real (a proxy that buffers SSE into uselessness, a gateway that does not forward it), which is why the knob exists rather than the behaviour being fixed.

Trait Implementations§

Source§

impl Debug for Anthropic

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Redacts the key. Deriving Debug would print it into every log line and span that touches the provider.

Source§

impl ModelProvider for Anthropic

Source§

fn request_profile(&self, model: &ModelId) -> Value

Stable, non-secret configuration that changes the provider wire request. Read more
Source§

fn complete<'life0, 'life1, 'async_trait>( &'life0 self, request: Request<'life1>, ) -> Pin<Box<dyn Future<Output = Result<Completion, ModelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Complete a prompt. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more