@@ -3,12 +3,11 @@ pcx_content_type: configuration
33title : OpenAI compatible API endpoints
44sidebar :
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://
2221import OpenAI from " openai" ;
2322
2423const 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
2929const 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