@@ -24,6 +24,28 @@ luarocks install lua-openai
2424
2525## Quick Usage
2626
27+ Using the Responses API:
28+
29+ ``` lua
30+ local openai = require (" openai" )
31+ local client = openai .new (os.getenv (" OPENAI_API_KEY" ))
32+
33+ local status , response = client :create_response ({
34+ {role = " system" , content = " You are a Lua programmer" },
35+ {role = " user" , content = " Write a 'Hello world' program in Lua" }
36+ }, {
37+ model = " gpt-4.1" ,
38+ temperature = 0.5
39+ })
40+
41+ if status == 200 then
42+ -- the JSON response is automatically parsed into a Lua object
43+ print (response .output [1 ].content [1 ].text )
44+ end
45+ ```
46+
47+ Using the Chat Completions API:
48+
2749``` lua
2850local openai = require (" openai" )
2951local client = openai .new (os.getenv (" OPENAI_API_KEY" ))
@@ -42,12 +64,14 @@ if status == 200 then
4264end
4365```
4466
67+
4568## Chat Session Example
4669
4770A chat session instance can be created to simplify managing the state of a back
48- and forth conversation with the ChatGPT API. Note that chat state is stored
49- locally in memory, each new message is appended to the list of messages, and
50- the output is automatically appended to the list for the next request.
71+ and forth conversation with the ChatGPT Chat Completions API. Note that chat
72+ state is stored locally in memory, each new message is appended to the list of
73+ messages, and the output is automatically appended to the list for the next
74+ request.
5175
5276``` lua
5377local openai = require (" openai" )
0 commit comments