Expand description
This module will contain the low-level request and response logic,
leveraging reqwest
to communicate with the OpenAI endpoints.
The api
module contains low-level functions for making HTTP requests to the OpenAI API.
It handles authentication headers, organization headers, error parsing, and JSON (de)serialization.
§Usage
This module is not typically used directly. Instead, higher-level modules (e.g., for Completions, Chat, Embeddings, etc.) will call these functions to perform network requests.
Functions§
- parse_
error_ response - Attempts to parse the OpenAI error body. If successful, returns
Err(OpenAIError::APIError)
. Otherwise, returns a generic error based on the HTTP status code or raw text. - post_
json_ stream - Sends a POST request with a JSON body to the given
endpoint
and returns a stream of responses. This is designed for endpoints that support streaming responses (e.g., Chat Completions withstream = true
).