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
impl Anthropic
pub const DEFAULT_TIMEOUT: Duration
Sourcepub const VERSION: &'static str = "2023-06-01"
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.
Sourcepub fn new(key: impl Into<String>) -> Result<Self, ModelError>
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.
Sourcepub const fn timeout(self, timeout: Duration) -> Self
pub const fn timeout(self, timeout: Duration) -> Self
Bound connection, generation, and response streaming as one operation.
Sourcepub fn base(self, base: impl Into<String>) -> Self
pub fn base(self, base: impl Into<String>) -> Self
Point at a different host — a gateway, or a test server.
Sourcepub fn structured_via(self, mode: SchemaMode) -> Self
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.
Sourcepub fn structured_via_for(
self,
model: impl Into<String>,
mode: SchemaMode,
) -> Self
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.
Sourcepub fn egress(self, egress: Egress) -> Self
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.
Sourcepub const fn buffered(self) -> Self
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 ModelProvider for Anthropic
impl ModelProvider for Anthropic
Auto Trait Implementations§
impl !RefUnwindSafe for Anthropic
impl !UnwindSafe for Anthropic
impl Freeze for Anthropic
impl Send for Anthropic
impl Sync for Anthropic
impl Unpin for Anthropic
impl UnsafeUnpin for Anthropic
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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