OpenAI.Responses.Client (openai_responses v0.3.0)
HTTP client for the OpenAI Responses API.
This module handles the communication with OpenAI's API, including authentication, request formatting, and response parsing.
Summary
Functions
Creates a new API client.
Makes a request to the OpenAI API.
Streams a response from the OpenAI API.
Functions
Creates a new API client.
Options
:api_key
- Your OpenAI API key (overrides environment variable):api_base
- The base URL for API requests (default: "https://api.openai.com/v1"):req_options
- Additional options to pass to Req:request_logger
- Optional 1-arity function to log requests. Receives theReq.Request
struct before the request is sent.
Makes a request to the OpenAI API.
Parameters
client
- The client fromnew/1
method
- The HTTP method (:get, :post, :delete, etc.)path
- The API path (e.g., "/responses")body
- The request body (for POST, PUT, etc.)query
- Query parameters
Returns
{:ok, response}
- On success{:error, error}
- On failure
@spec stream(map(), String.t(), map()) :: Enumerable.t()
Streams a response from the OpenAI API.
Uses Req's built-in streaming capabilities. This implementation creates a proper Elixir Stream that processes events as they arrive from the API.
Parameters
client
- The client fromnew/1
path
- The API path (e.g., "/responses")body
- The request body
Returns
- A stream of events that can be processed in real-time