pub struct RequestOptions {
pub auth: Auth,
pub extra_headers: HeaderMap,
}Expand description
Per-request authentication and header options.
Passed to every request method instead of a bare API key. Authentication
headers (Auth) are applied first; RequestOptions::extra_headers
are applied afterwards, so they can supply additional credentials of
their own.
Fields§
§auth: AuthHow the request authenticates itself. Defaults to Auth::None.
extra_headers: HeaderMapAdditional headers attached verbatim to the request, e.g.
OpenAI-Organization, Azure api-key or Anthropic
anthropic-version.
Implementations§
Source§impl RequestOptions
impl RequestOptions
Sourcepub fn bearer(token: impl Into<String>) -> Self
pub fn bearer(token: impl Into<String>) -> Self
Creates options authenticating with Authorization: Bearer <token>,
the scheme used by OpenAI and most compatible providers.
Sourcepub fn with_header(self, name: &str, value: &str) -> Result<Self, OapiError>
pub fn with_header(self, name: &str, value: &str) -> Result<Self, OapiError>
Adds an extra header, e.g. api-key for Azure or x-api-key plus
anthropic-version for Anthropic.
Header names and values are validated eagerly; use
RequestOptions::extra_headers directly if you already hold typed
HeaderName/HeaderValues.
§Errors
Returns OapiError::InvalidHeader if the name or value is not a
valid HTTP header.