Skip to content

Commit 83e0da3

Browse files
committed
add openrouter example
1 parent 203d603 commit 83e0da3

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ with OpenResty using
88
This project implements both the classic Chat Completions API in addition to
99
the modern Responses API.
1010

11+
Compatibility clients for [Google Gemini](#using-with-google-gemini) and
12+
[OpenRouter](#using-with-openrouter) are also included.
13+
1114
<details>
1215
<summary>AI Generated Disclaimer</summary>
1316

examples/openrouter/basic.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Example: Using OpenRouter with chat completions
2+
-- Requires OPENROUTER_API_KEY environment variable
3+
4+
local OpenRouter = require("openai.compat.openrouter")
5+
local client = OpenRouter.new(os.getenv("OPENROUTER_API_KEY"))
6+
7+
local status, response = client:create_chat_completion({
8+
{role = "user", content = "Write a haiku about Lua programming"}
9+
}, {
10+
model = "xiaomi/mimo-v2-flash:free"
11+
})
12+
13+
if status == 200 then
14+
print(response.choices[1].message.content)
15+
else
16+
print("Error:", status)
17+
if response and response.error then
18+
print(response.error.message)
19+
end
20+
end

0 commit comments

Comments
 (0)