usage/req.bend relies on unsafe/foreign
raw source on the hub · import cswap-bend-cli@0.1.0.0/usage/req.bend as Req
4 imports
import Base import ../http.bend as Http import ../json.bend as Json import ./text.bend as UText
Types
type Err source · line 11 · raw
Data
kind: http-<code>, timeout, network, bad-response (the reference's _classify_usage_error names); retry: Retry-After seconds when sent; body: the response text, kept only to tell a scope 403 from other 403s (never shown).
Err@kind:String -> @retry:Maybe<&2, U32> -> @body:String -> Err
Definitions
def retry.int source · line 14 · raw
@ps:List<&2, String> -> Maybe<&2, U32>
def retry.norm source · line 21 · raw
@m:Maybe<&2, String> -> Maybe<&2, U32>
def retry.zero source · line 28 · raw
@m:Maybe<&2, String> -> Maybe<&2, U32>
def retry.neg source · line 35 · raw
@neg:Bool -> @+raw:String -> Maybe<&2, U32>
def retry.of source · line 42 · raw
@m:Maybe<&2, String> -> Maybe<&2, U32>
def retry_after source · line 51 · raw
@+head:String -> Maybe<&2, U32>
Retry-After in whole seconds (the seconds form only; fractions drop, a negative value is 0, anything else is none).
def http.err source · line 54 · raw
@+r:0x0717344745a30ebad1f19045228e8f18/http.Reply -> Err
def ok2xx source · line 59 · raw
@+st:U32 -> Bool
def scope_error source · line 63 · raw
@e:Err -> Bool
The reference raises on a 403 whose body says the token lacks scope.
def is_429 source · line 68 · raw
@e:Err -> Bool
def bad source · line 73 · raw
@kind:String -> Err
def probe.pick source · line 78 · raw
@data:Maybe<&2, 0x0717344745a30ebad1f19045228e8f18/json.Json> -> @ok:Bool -> @e:Err -> Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json>
def probe.reply source · line 87 · raw
@+r:0x0717344745a30ebad1f19045228e8f18/http.Reply -> Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json>
def probe.result source · line 92 · raw
@r:Result<&2, &2, String, 0x0717344745a30ebad1f19045228e8f18/http.Reply> -> Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json>
def probe source · line 101 · raw
@token:String -> IO(Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json>)
The one-token Messages call whose rate-limit headers carry the usage; a non-2xx that still has the headers (429 when exhausted) is a valid reading.
def body.obj source · line 111 · raw
@j:0x0717344745a30ebad1f19045228e8f18/json.Json -> Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json>
data.get on a non-object raises AttributeError in the reference.
def body.json source · line 118 · raw
@ok:Result<&2, &2, String, 0x0717344745a30ebad1f19045228e8f18/json.Json> -> Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json>
def usage.pick source · line 125 · raw
@ok:Bool -> @+body:String -> @e:Err -> Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json>
def usage.reply source · line 132 · raw
@+r:0x0717344745a30ebad1f19045228e8f18/http.Reply -> Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json>
def usage.result source · line 137 · raw
@r:Result<&2, &2, String, 0x0717344745a30ebad1f19045228e8f18/http.Reply> -> Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json>
def usage.get source · line 144 · raw
@token:String -> IO(Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json>)
def fallback.pick source · line 152 · raw
@p:Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json> -> @orig:Err -> Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json>
A probe that failed after a usage-endpoint 429 hands back the 429.
def fallback source · line 159 · raw
@+token:String -> @+orig:Err -> IO(Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json>)
def route source · line 163 · raw
@scope:Bool -> @rl:Bool -> @e:Err -> @token:String -> IO(Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json>)
def usage.next source · line 172 · raw
@r:Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json> -> @token:String -> IO(Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json>)
def request_data.go source · line 179 · raw
@+token:String -> @inference_only:Bool -> IO(Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json>)
def request_usage_data source · line 189 · raw
@token:String -> @inference_only:Bool -> IO(Result<&2, &2, Err, 0x0717344745a30ebad1f19045228e8f18/json.Json>)
request_usage_data: the usage endpoint, with the probe for an inference-only token, after a scope 403, and after a 429 (whose own error stands if the probe fails too).