Skip to content

Commit 6493c8f

Browse files
committed
Adds Responses example
1 parent b3ce9fc commit 6493c8f

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/content/docs/workers-ai/configuration/open-ai-compatibility.mdx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ pcx_content_type: configuration
33
title: OpenAI compatible API endpoints
44
sidebar:
55
order: 3
6-
76
---
87

9-
import { Render } from "~/components"
8+
import { Render } from "~/components";
109

11-
<Render file="openai-compatibility" /> <br/>
10+
<Render file="openai-compatibility" /> <br />
1211

1312
## Usage
1413

@@ -22,20 +21,26 @@ With OpenAI compatible endpoints,you can leverage the [openai-node sdk](https://
2221
import OpenAI from "openai";
2322

2423
const openai = new OpenAI({
25-
apiKey: env.CLOUDFLARE_API_KEY,
26-
baseURL: `https://api.cloudflare.com/client/v4/accounts/${env.CLOUDFLARE_ACCOUNT_ID}/ai/v1`
27-
});
24+
apiKey: env.CLOUDFLARE_API_KEY,
25+
baseURL: `https://api.cloudflare.com/client/v4/accounts/${env.CLOUDFLARE_ACCOUNT_ID}/ai/v1`,
26+
});
2827

28+
// Use chat completions
2929
const chatCompletion = await openai.chat.completions.create({
30-
messages: [{ role: "user", content: "Make some robot noises" }],
31-
model: "@cf/meta/llama-3.1-8b-instruct",
32-
});
30+
messages: [{ role: "user", content: "Make some robot noises" }],
31+
model: "@cf/meta/llama-3.1-8b-instruct",
32+
});
3333

34-
const embeddings = await openai.embeddings.create({
35-
model: "@cf/baai/bge-large-en-v1.5",
36-
input: "I love matcha"
37-
});
34+
// Use responses
35+
const response = await openai.responses.create({
36+
model: "@cf/openai/gpt-oss-120b",
37+
input: "Talk to me about open source",
38+
});
3839

40+
const embeddings = await openai.embeddings.create({
41+
model: "@cf/baai/bge-large-en-v1.5",
42+
input: "I love matcha",
43+
});
3944
```
4045

4146
```bash title="cURL example"

0 commit comments

Comments
 (0)