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. 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 —
and, since RunConfig::concurrency,
correctness under genuinely simultaneous probes.
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 fn with_limit(self, permits: usize) -> Self
pub fn with_limit(self, permits: usize) -> Self
Cap how many requests this client may have in flight at once.
§Why the cap lives here and not in the scheduler
Concurrency has two units in this crate and only one of them is worth
bounding. The scheduler’s unit is the step, and steps are wildly
uneven — the capability battery is a dozen requests, stop_sequence is
one — so “four steps at a time” says almost nothing about how much
traffic is actually in the air. The unit that matters to whoever is
answering is the request, and every request in the suite passes
through this type.
That matters most to the caller this exists for: one probing somebody else’s endpoint, where the far end has a concurrency budget of its own that it did not agree to spend on being examined. Overrun it and the endpoint starts refusing — and a refusal is indistinguishable, from here, from the endpoint being broken. A run that saturates its subject measures the saturation.
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.