Skip to main content

Module options

Module options 

Source
Expand description

Per-request authentication and header options.

Every request method takes a RequestOptions value, which decides how the request authenticates and which extra headers are attached. The default is no authentication; RequestOptions::bearer reproduces the classic Authorization: Bearer <token> behavior of OpenAI and most compatible providers.

§Examples

Plain OpenAI-style bearer auth:

use openai_interface::rest::RequestOptions;

let options = RequestOptions::bearer("sk-...");

Azure OpenAI authenticates with an api-key header instead:

use openai_interface::rest::RequestOptions;

let options = RequestOptions::new()
    .with_header("api-key", "...")
    .unwrap();

Anthropic uses x-api-key plus a version header:

use openai_interface::rest::RequestOptions;

let options = RequestOptions::new()
    .with_header("x-api-key", "...")
    .unwrap()
    .with_header("anthropic-version", "2023-06-01")
    .unwrap();

Extra headers may also be layered on top of bearer auth, e.g. the OpenAI-Organization header:

use openai_interface::rest::RequestOptions;

let options = RequestOptions::bearer("sk-...")
    .with_header("OpenAI-Organization", "org-...")
    .unwrap();

Structs§

RequestOptions
Per-request authentication and header options.

Enums§

Auth
How a request authenticates itself.