Skip to content

Commit a3d696e

Browse files
committed
document more api client methods
1 parent 9f5ea38 commit a3d696e

File tree

1 file changed

+94
-2
lines changed

1 file changed

+94
-2
lines changed

README.md

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ The `openai` module returns a table with the following fields:
222222
- `OpenAI`: A client for sending requests to the OpenAI API.
223223
- `new`: An alias to `OpenAI` to create a new instance of the OpenAI client
224224
- `ChatSession`: A class for managing chat sessions and history with the OpenAI API.
225-
- `VERSION = "1.1.0"`: The current version of the library
225+
- `VERSION = "1.5.0"`: The current version of the library
226226

227227
### Classes
228228

@@ -236,7 +236,7 @@ Constructor for the OpenAI client.
236236

237237
- `api_key`: Your OpenAI API key.
238238
- `config`: An optional table of configuration options, with the following shape:
239-
- `http_provider`: A string specifying the HTTP module name used for requests, or `nil`. If not provided, the library will automatically use "lapis.nginx.http" in an ngx environment, or "ssl.https" otherwise.
239+
- `http_provider`: A string specifying the HTTP module name used for requests, or `nil`. If not provided, the library will automatically use "lapis.nginx.http" in an ngx environment, or "socket.http" otherwise.
240240

241241
```lua
242242
local openai = require("openai")
@@ -251,6 +251,18 @@ abstraction over the chat completions API that stores the chat history. You can
251251
append new messages to the history and request completions to be generated from
252252
it. By default, the completion is appended to the history.
253253

254+
##### `client:new_responses_chat_session(...)`
255+
256+
Creates a new ResponsesChatSession instance for the Responses API. Similar to
257+
ChatSession but uses OpenAI's Responses API which handles conversation state
258+
server-side via `previous_response_id`.
259+
260+
- `opts`: Optional configuration table
261+
- `model`: Model to use (defaults to client's default_model)
262+
- `instructions`: System instructions for the conversation
263+
- `tools`: Array of tool definitions
264+
- `previous_response_id`: Resume from a previous response
265+
254266
##### `client:chat(messages, opts, chunk_callback)`
255267

256268
Sends a request to the `/chat/completions` endpoint.
@@ -282,6 +294,86 @@ Sends a request to the `/embeddings` endpoint.
282294
Returns HTTP status, response object, and output headers. The response object
283295
will be decoded from JSON if possible, otherwise the raw string is returned.
284296

297+
##### `client:create_response(input, opts, stream_callback)`
298+
299+
Sends a request to the `/responses` endpoint (Responses API).
300+
301+
- `input`: A string or array of message objects (with `role` and `content` fields)
302+
- `opts`: Additional options passed directly to the API (eg. model, temperature, instructions, tools, previous_response_id, etc.) https://platform.openai.com/docs/api-reference/responses
303+
- `stream_callback`: Optional function called for each parsed chunk when `stream = true` is passed in opts
304+
305+
Returns HTTP status, response object, and output headers. The response object
306+
will be decoded from JSON if possible, otherwise the raw string is returned.
307+
308+
##### `client:response(response_id)`
309+
310+
Retrieves a stored response by ID from the `/responses/{id}` endpoint.
311+
312+
- `response_id`: The ID of the response to retrieve
313+
314+
Returns HTTP status, response object, and output headers.
315+
316+
##### `client:delete_response(response_id)`
317+
318+
Deletes a stored response.
319+
320+
- `response_id`: The ID of the response to delete
321+
322+
Returns HTTP status, response object, and output headers.
323+
324+
##### `client:cancel_response(response_id)`
325+
326+
Cancels an in-progress streaming response.
327+
328+
- `response_id`: The ID of the response to cancel
329+
330+
Returns HTTP status, response object, and output headers.
331+
332+
##### `client:moderation(input, opts)`
333+
334+
Sends a request to the `/moderations` endpoint to check content against OpenAI's content policy.
335+
336+
- `input`: A string or array of strings to classify
337+
- `opts`: Additional options passed directly to the API
338+
339+
Returns HTTP status, response object, and output headers.
340+
341+
##### `client:models()`
342+
343+
Lists available models from the `/models` endpoint.
344+
345+
Returns HTTP status, response object, and output headers.
346+
347+
##### `client:files()`
348+
349+
Lists uploaded files from the `/files` endpoint.
350+
351+
Returns HTTP status, response object, and output headers.
352+
353+
##### `client:file(file_id)`
354+
355+
Retrieves information about a specific file.
356+
357+
- `file_id`: The ID of the file to retrieve
358+
359+
Returns HTTP status, response object, and output headers.
360+
361+
##### `client:delete_file(file_id)`
362+
363+
Deletes a file.
364+
365+
- `file_id`: The ID of the file to delete
366+
367+
Returns HTTP status, response object, and output headers.
368+
369+
##### `client:image_generation(params)`
370+
371+
Sends a request to the `/images/generations` endpoint to generate images.
372+
373+
- `params`: Parameters for image generation (prompt, n, size, etc.) https://platform.openai.com/docs/api-reference/images/create
374+
375+
Returns HTTP status, response object, and output headers.
376+
285377
#### ChatSession
286378

287379
This class manages chat sessions and history with the OpenAI API. Typically

0 commit comments

Comments
 (0)