pub struct Client {
pub endpoint: Endpoint,
pub request_count: AtomicU32,
/* private fields */
}Fields§
§endpoint: Endpoint§request_count: AtomicU32Every request the run has made, for the report’s request ledger.
Atomic rather than Cell so a probe future stays Send. Probes run
sequentially and nothing here is contended; what the atomic buys is the
ability to await this engine from a multi-threaded runtime — an
embedder’s request handler cannot hold a !Send future.
Implementations§
Source§impl Client
impl Client
pub fn new(endpoint: Endpoint) -> Result<Self>
Sourcepub fn with_http(endpoint: Endpoint, http: Client) -> Self
pub fn with_http(endpoint: Endpoint, http: Client) -> Self
Build on a caller-supplied HTTP client.
An embedder generally already has one, configured for its own network: a proxy it must egress through, a connection pool it wants shared, a root store it pins. Rebuilding that here would either duplicate the configuration or quietly ignore it.
The caller owns the timeout and the redirect policy that come with the
client it passes. Both matter to what the probes mean — a client that
follows redirects can be bounced to a different host mid-run without
the report saying so — so a caller that has no strong opinion should
use Client::new.
Sourcepub async fn post_raw(
&self,
path: &str,
body: &Value,
opts: &RequestOpts,
) -> Result<RawResponse>
pub async fn post_raw( &self, path: &str, body: &Value, opts: &RequestOpts, ) -> Result<RawResponse>
POST a JSON body and return the raw response without interpreting it.
pub async fn get_raw( &self, path: &str, opts: &RequestOpts, ) -> Result<RawResponse>
Sourcepub async fn chat(
&self,
req: &ChatRequest,
) -> Result<(ChatResponse, RawResponse)>
pub async fn chat( &self, req: &ChatRequest, ) -> Result<(ChatResponse, RawResponse)>
Send a chat request and parse it. Returns both the parsed view and the raw response, because several probes assert on headers and status.
pub async fn chat_with( &self, req: &ChatRequest, opts: &RequestOpts, ) -> Result<(ChatResponse, RawResponse)>
Sourcepub async fn stream(&self, req: &ChatRequest) -> Result<StreamResult>
pub async fn stream(&self, req: &ChatRequest) -> Result<StreamResult>
Stream a chat request, timing the first content-bearing event.
Sourcepub async fn count_tokens(&self, req: &ChatRequest) -> Option<Result<u32>>
pub async fn count_tokens(&self, req: &ChatRequest) -> Option<Result<u32>>
Anthropic’s authoritative token counter. None when the protocol has
no such route; Err when the route exists but the endpoint refused.