def probe

cswap-bend-cli@0.1.0.0 · usage/req.bend:99

import cswap-bend-cli@0.1.0.0/usage/req.bend as Req
import Base
import cswap-bend-cli@0.1.0.0/http.bend as Http
import cswap-bend-cli@0.1.0.0/json.bend as Json
import cswap-bend-cli@0.1.0.0/usage/text.bend as UText

99# The one-token Messages call whose rate-limit headers carry the usage; a
100# non-2xx that still has the headers (429 when exhausted) is a valid reading.
101def probe(token: String) -> IO(Result<&2, &2, Err, Json.Json>):
102  IO.bind(Result<&2, &2, String, Http.Reply>, Result<&2, &2, Err, Json.Json>,
103    Http.request("POST", UText.messages_url(),
104      [("Authorization", "Bearer " ++ token), ("anthropic-version", "2023-06-01"),
105       ("anthropic-beta", "claude-code-20250219,oauth-2025-04-20"), ("content-type", "application/json"),
106       ("User-Agent", UText.user_agent())],
107      UText.probe.body(), 20),
108    r => IO.pure(Result<&2, &2, Err, Json.Json>, probe.result(r)))

Uses (16)

Used by (3)