Skip to content

Commit 561b0fe

Browse files
Revert "tab test"
This reverts commit d218ea1.
1 parent d218ea1 commit 561b0fe

File tree

1 file changed

+89
-81
lines changed

1 file changed

+89
-81
lines changed

src/content/docs/ai-gateway/providers/openai.mdx

Lines changed: 89 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -38,96 +38,104 @@ When making requests to OpenAI, ensure you have the following:
3838
- An active OpenAI API token.
3939
- The name of the OpenAI model you want to use.
4040

41-
## Examples
42-
43-
<Tabs syncKey="apiExamples">
44-
<TabItem label="cURL">
45-
<div>
46-
<h3>Chat completions endpoint</h3>
47-
<pre>
48-
{`curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions \\
49-
--header 'Authorization: Bearer {openai_token}' \\
50-
--header 'Content-Type: application/json' \\
51-
--data '{
52-
"model": "gpt-4o-mini",
53-
"messages": [
54-
{
55-
"role": "user",
56-
"content": "What is Cloudflare?"
57-
}
58-
]
59-
}'`}
60-
</pre>
61-
<h3>Responses endpoint</h3>
62-
<pre>
63-
{`curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/responses \\
64-
--header 'Authorization: Bearer {openai_token}' \\
65-
--header 'Content-Type: application/json' \\
66-
--data '{
67-
"model": "gpt-4.1",
68-
"input": [
69-
{
70-
"role": "user",
71-
"content": "Write a one-sentence bedtime story about a unicorn."
72-
}
73-
]
74-
}'`}
75-
</pre>
76-
</div>
77-
</TabItem>
78-
<TabItem label="JavaScript">
79-
<div>
80-
<h3>Chat completions endpoint</h3>
81-
<pre>
82-
{`import OpenAI from "openai";
83-
const apiKey = "my api key";
41+
## Chat completions endpoint
42+
43+
### cURL example
44+
45+
```bash
46+
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions \
47+
--header 'Authorization: Bearer {openai_token}' \
48+
--header 'Content-Type: application/json' \
49+
--data '{
50+
"model": "gpt-4o-mini",
51+
"messages": [
52+
{
53+
"role": "user",
54+
"content": "What is Cloudflare?"
55+
}
56+
]
57+
}'
58+
```
59+
60+
### JavaScript SDK example
61+
62+
```js
63+
import OpenAI from "openai";
64+
65+
const apiKey = "my api key"; // or process.env["OPENAI_API_KEY"]
8466
const accountId = "{account_id}";
8567
const gatewayId = "{gateway_id}";
86-
const baseURL = \`https://gateway.ai.cloudflare.com/v1/\${accountId}/\${gatewayId}/openai\`;
68+
const baseURL = `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/openai`;
69+
8770
const openai = new OpenAI({
88-
apiKey,
89-
baseURL,
71+
apiKey,
72+
baseURL,
9073
});
74+
9175
try {
92-
const model = "gpt-3.5-turbo-0613";
93-
const messages = [{ role: "user", content: "What is a neuron?" }];
94-
const maxTokens = 100;
95-
const chatCompletion = await openai.chat.completions.create({
96-
model,
97-
messages,
98-
max_tokens: maxTokens,
99-
});
100-
const response = chatCompletion.choices[0].message;
101-
console.log(response);
76+
const model = "gpt-3.5-turbo-0613";
77+
const messages = [{ role: "user", content: "What is a neuron?" }];
78+
const maxTokens = 100;
79+
const chatCompletion = await openai.chat.completions.create({
80+
model,
81+
messages,
82+
max_tokens: maxTokens,
83+
});
84+
const response = chatCompletion.choices[0].message;
85+
console.log(response);
10286
} catch (e) {
103-
console.error(e);
104-
}`}
105-
</pre>
106-
<h3>Responses endpoint</h3>
107-
<pre>
108-
{`import OpenAI from "openai";
109-
const apiKey = "my api key";
87+
console.error(e);
88+
}
89+
```
90+
91+
## OpenAI Responses endpoint
92+
93+
### cURL example
94+
95+
```bash
96+
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/responses \
97+
--header 'Authorization: Bearer {openai_token}' \
98+
--header 'Content-Type: application/json' \
99+
--data '{
100+
"model": "gpt-4.1",
101+
"input": [
102+
{
103+
"role": "user",
104+
"content": "Write a one-sentence bedtime story about a unicorn."
105+
}
106+
]
107+
}'
108+
```
109+
110+
### JavaScript SDK example
111+
112+
```js
113+
import OpenAI from "openai";
114+
115+
const apiKey = "my api key"; // or process.env["OPENAI_API_KEY"]
110116
const accountId = "{account_id}";
111117
const gatewayId = "{gateway_id}";
112-
const baseURL = \`https://gateway.ai.cloudflare.com/v1/\${accountId}/\${gatewayId}/openai\`;
118+
const baseURL = `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/openai`;
119+
113120
const openai = new OpenAI({
114-
apiKey,
115-
baseURL,
121+
apiKey,
122+
baseURL,
116123
});
124+
117125
try {
118-
const model = "gpt-4.1";
119-
const input = [
120-
{ role: "user", content: "Write a one-sentence bedtime story about a unicorn." }
121-
];
122-
const response = await openai.responses.create({
123-
model,
124-
input,
125-
});
126-
console.log(response.output_text);
126+
const model = "gpt-4.1";
127+
const input = [
128+
{
129+
role: "user",
130+
content: "Write a one-sentence bedtime story about a unicorn.",
131+
},
132+
];
133+
const response = await openai.responses.create({
134+
model,
135+
input,
136+
});
137+
console.log(response.output_text);
127138
} catch (e) {
128-
console.error(e);
129-
}`}
130-
</pre>
131-
</div>
132-
</TabItem>
133-
</Tabs>
139+
console.error(e);
140+
}
141+
```

0 commit comments

Comments
 (0)