1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//! The names and defaults the SDK's behaviour is pinned to: the environment
//! variables, headers, API paths and defaults.
use ;
use ;
/// The response header carrying the server's identifier for a request.
pub const REQUEST_ID_HEADER: &str = "x-typesafe-request-id";
/// The server's identifier for a request, when `headers` carry one as text.
pub
/// The non-standard millisecond-precision companion to `Retry-After`.
pub const RETRY_AFTER_MS_HEADER: &str = "retry-after-ms";
// ------------------------------------------------- environment and defaults
/// The environment variable a client reads its API key from when none is
/// passed explicitly.
pub const API_KEY_ENV: &str = "TYPESAFE_API_KEY";
/// The environment variable a client reads its base URL from when none is
/// passed explicitly.
pub const BASE_URL_ENV: &str = "TYPESAFE_BASE_URL";
/// The environment variable a client reads its default model from when none
/// is passed explicitly.
pub const DEFAULT_MODEL_ENV: &str = "TYPESAFE_DEFAULT_MODEL";
/// The API root a client talks to when neither the caller nor
/// [`BASE_URL_ENV`] names one.
pub const DEFAULT_BASE_URL: &str = "https://api.typesafe.ai";
/// The model a request names when neither the call, the client nor
/// [`DEFAULT_MODEL_ENV`] names one.
pub const DEFAULT_MODEL: &str = "jev-latest";
/// The deadline each attempt of a request gets when the caller sets none.
///
/// It bounds one attempt from the first byte sent to the last byte received,
/// not the whole call: a retried call can take several of these.
pub const DEFAULT_TIMEOUT: Duration = from_secs;
/// The largest response body a client reads before giving up on it, in bytes.
///
/// A body is collected in memory before it is decoded, so without a cap a
/// broken or hostile endpoint could make one call hold as much memory as it
/// cared to send.
pub const DEFAULT_MAX_RESPONSE_BYTES: usize = 16 * 1024 * 1024;
// ------------------------------------------------------------ API paths
/// The path of the System One endpoint, appended to the base URL.
pub const SYSTEM_ONE_PATH: &str = "/v1/systemone";
/// The path of the model listing endpoint, appended to the base URL.
pub const MODELS_PATH: &str = "/v1/models";
// ------------------------------------------------------ request headers
//
// `http` keeps header names lower-cased, so these are spelled that way; on the
// wire HTTP/1.1 header names are case-insensitive and HTTP/2 requires lower
// case, so nothing is lost. The names `http` already defines (`authorization`,
// `accept`, `content-type`, `user-agent`) are used from `http::header` directly
// rather than restated here.
/// The header naming the SDK and its version on every request.
pub const SDK_HEADER: HeaderName = from_static;
/// The header naming the language runtime, operating system and architecture
/// on every request.
pub const RUNTIME_HEADER: HeaderName = from_static;
/// The header counting how many times a request has been retried, set by the
/// SDK on retries only. A caller-supplied one is dropped.
pub const RETRY_COUNT_HEADER: HeaderName = from_static;
/// The headers that frame a message or manage its connection, which belong
/// to the transport and are dropped from client defaults and per-call headers
/// on every protocol.
///
/// A caller's value for one of them disagrees with the body the SDK sends or
/// with how the transport runs the connection. HTTP/2 forbids the
/// connection-specific ones (RFC 9113, section 8.2.2), so hyper strips them
/// there; a `Content-Length` that disagrees with the body fails an HTTP/2
/// stream and leaves an HTTP/1.1 exchange waiting for bytes that never come,
/// on a connection other calls share. `Host` is not among them; see
/// [`ClientBuilder::default_header`](crate::ClientBuilder::default_header).
pub const TRANSPORT_HEADERS: = ;
/// The media type of every request body and of every response the SDK accepts.
pub const JSON_CONTENT_TYPE: HeaderValue = from_static;
/// The headers the SDK sets on every request, which neither a client default
/// nor a per-call header can replace.
///
/// They say who is calling and with which credential; a caller who could
/// override them could send a request the SDK cannot vouch for. The Python
/// SDK protects the same five (`_core/transport.py`), and `Content-Type` is
/// forced on a request with a body on top of them.
pub const PROTECTED_HEADERS: =
;
/// The header names whose values are credentials, and so are never logged.
///
/// Lower-cased, because that is how `http` stores every name. A name that
/// merely contains `token` or `secret` is treated the same way; that rule lives
/// with the redaction that applies it, which exists only when events do.
pub const SECRET_HEADERS: =
;
// ------------------------------------------------------ SDK identification
/// What the SDK calls itself in `User-Agent` and [`SDK_HEADER`], as
/// `typesafe-sdk-rust/<version>`.
///
/// Deliberately not the official Python SDK's `typesafe-sdk/<version>`: the
/// server may count or treat SDKs by this value, and a port must not be
/// mistaken for the SDK it is a port of.
pub const SDK_IDENTIFIER: HeaderValue =
from_static;
/// What the SDK sends in [`RUNTIME_HEADER`], as `rust (<os>; <arch>)`.
///
/// `std::env::consts` holds the target the crate was compiled for, such as
/// `macos` and `aarch64`. Those are constants but not literals, and `concat!`
/// takes only literals, so the value is built on first use and kept for the
/// life of the process.
pub static RUNTIME_IDENTIFIER: = new;