Skip to content

Commit 0610dbb

Browse files
committed
feat: added baseten and ideogram docs
1 parent 98e947a commit 0610dbb

File tree

2 files changed

+294
-0
lines changed

2 files changed

+294
-0
lines changed
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
---
2+
title: Baseten
3+
pcx_content_type: get-started
4+
---
5+
6+
import { Render, Tabs, TabItem } from "~/components";
7+
8+
[Baseten](https://www.baseten.co/) provides infrastructure for building and deploying machine learning models at scale. Baseten offers access to various language models through a unified chat completions API.
9+
10+
## Endpoint
11+
12+
```txt
13+
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/baseten
14+
```
15+
16+
## Prerequisites
17+
18+
When making requests to Baseten, ensure you have the following:
19+
20+
- Your AI Gateway Account ID.
21+
- Your AI Gateway gateway name.
22+
- An active Baseten API token.
23+
- The name of the Baseten model you want to use.
24+
25+
## OpenAI-compatible chat completions API
26+
27+
Baseten provides an OpenAI-compatible chat completions API for supported models.
28+
29+
### cURL
30+
31+
```bash title="Example fetch request"
32+
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/baseten/v1/chat/completions \
33+
--header 'Authorization: Bearer {baseten_api_token}' \
34+
--header 'Content-Type: application/json' \
35+
--data '{
36+
"model": "openai/gpt-oss-120b",
37+
"messages": [
38+
{
39+
"role": "user",
40+
"content": "What is Cloudflare?"
41+
}
42+
]
43+
}'
44+
```
45+
46+
### Use OpenAI SDK with JavaScript
47+
48+
<Tabs syncKey="sdk">
49+
<TabItem label="Javascript" icon="seti:javascript">
50+
51+
```js title="JavaScript"
52+
import OpenAI from "openai";
53+
54+
const apiKey = "{baseten_api_token}";
55+
const accountId = "{account_id}";
56+
const gatewayId = "{gateway_id}";
57+
const baseURL = `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/baseten`;
58+
59+
const openai = new OpenAI({
60+
apiKey,
61+
baseURL,
62+
});
63+
64+
const model = "openai/gpt-oss-120b";
65+
const messages = [{ role: "user", content: "What is Cloudflare?" }];
66+
67+
const chatCompletion = await openai.chat.completions.create({
68+
model,
69+
messages,
70+
});
71+
72+
console.log(chatCompletion);
73+
```
74+
75+
</TabItem>
76+
<TabItem label="Javascript (Workers)" icon="seti:javascript">
77+
78+
```js title="JavaScript"
79+
import OpenAI from "openai";
80+
import { useAIGateway, ProviderAuth } from "@cloudflare/ai-gateway";
81+
82+
export default {
83+
async fetch(request, env) {
84+
useAIGateway({ binding: env.AI, gateway: "test-gateway" });
85+
86+
const unifiedAuth = ProviderAuth.unifiedBilling();
87+
88+
const openai = new OpenAI({
89+
apiKey: unifiedAuth,
90+
baseURL: "https://api.baseten.co",
91+
});
92+
93+
const model = "openai/gpt-oss-120b";
94+
const messages = [{ role: "user", content: "What is Cloudflare?" }];
95+
96+
const chatCompletion = await openai.chat.completions.create({
97+
model,
98+
messages,
99+
});
100+
101+
return Response.json(chatCompletion);
102+
},
103+
};
104+
```
105+
106+
</TabItem>
107+
</Tabs>
108+
109+
<Render
110+
file="chat-completions-providers"
111+
product="ai-gateway"
112+
params={{
113+
name: "Baseten",
114+
jsonexample: `
115+
{
116+
"model": "baseten/{model}"
117+
}`
118+
}}
119+
/>
120+
121+
## Model-specific endpoints
122+
123+
For models that don't use the OpenAI-compatible API, you can access them through their specific model endpoints.
124+
125+
### cURL
126+
127+
```bash title="Example fetch request"
128+
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/baseten/model/{model_id} \
129+
--header 'Authorization: Bearer {baseten_api_token}' \
130+
--header 'Content-Type: application/json' \
131+
--data '{
132+
"prompt": "What is Cloudflare?",
133+
"max_tokens": 100
134+
}'
135+
```
136+
137+
### Use with JavaScript
138+
139+
<Tabs syncKey="sdk">
140+
<TabItem label="Javascript" icon="seti:javascript">
141+
142+
```js title="JavaScript"
143+
const accountId = "{account_id}";
144+
const gatewayId = "{gateway_id}";
145+
const basetenApiToken = "{baseten_api_token}";
146+
const modelId = "{model_id}";
147+
const baseURL = `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/baseten`;
148+
149+
const response = await fetch(`${baseURL}/model/${modelId}`, {
150+
method: "POST",
151+
headers: {
152+
"Authorization": `Bearer ${basetenApiToken}`,
153+
"Content-Type": "application/json",
154+
},
155+
body: JSON.stringify({
156+
prompt: "What is Cloudflare?",
157+
max_tokens: 100,
158+
}),
159+
});
160+
161+
const result = await response.json();
162+
console.log(result);
163+
```
164+
165+
</TabItem>
166+
<TabItem label="Javascript (Workers)" icon="seti:javascript">
167+
168+
```js title="JavaScript (Workers)"
169+
import { useAIGateway, ProviderAuth } from "@cloudflare/ai-gateway";
170+
171+
export default {
172+
async fetch(request, env) {
173+
useAIGateway({ binding: env.AI, gateway: "test-gateway" });
174+
175+
const unifiedAuth = ProviderAuth.unifiedBilling();
176+
const modelId = "{model_id}";
177+
178+
const response = await fetch(`https://model-${modelId}.api.baseten.co/production/predict`, {
179+
method: "POST",
180+
headers: {
181+
"Authorization": unifiedAuth,
182+
"Content-Type": "application/json",
183+
},
184+
body: JSON.stringify({
185+
prompt: "What is Cloudflare?",
186+
max_tokens: 100,
187+
}),
188+
});
189+
190+
const result = await response.json();
191+
return Response.json(result);
192+
},
193+
};
194+
```
195+
196+
</TabItem>
197+
</Tabs>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: Ideogram
3+
pcx_content_type: get-started
4+
---
5+
6+
import { Tabs, TabItem } from "~/components";
7+
8+
[Ideogram](https://ideogram.ai/) provides advanced text-to-image generation models with exceptional text rendering capabilities and visual quality.
9+
10+
## Endpoint
11+
12+
```txt
13+
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/ideogram
14+
```
15+
16+
## Prerequisites
17+
18+
When making requests to Ideogram, ensure you have the following:
19+
20+
- Your AI Gateway Account ID.
21+
- Your AI Gateway gateway name.
22+
- An active Ideogram API key.
23+
- The name of the Ideogram model you want to use (e.g., `V_3`).
24+
25+
## Examples
26+
27+
### cURL
28+
29+
```bash title="Example fetch request"
30+
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/ideogram/v1/ideogram-v3/generate \
31+
--header 'Api-Key: {ideogram_api_key}' \
32+
--header 'Content-Type: application/json' \
33+
--data '{
34+
"prompt": "A serene landscape with mountains and a lake at sunset",
35+
"model": "V_3"
36+
}'
37+
```
38+
39+
### Use with JavaScript
40+
41+
<Tabs syncKey="sdk">
42+
<TabItem label="Javascript" icon="seti:javascript">
43+
44+
```js title="JavaScript"
45+
const accountId = "{account_id}";
46+
const gatewayId = "{gateway_id}";
47+
const ideogramApiKey = "{ideogram_api_key}";
48+
const baseURL = `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/ideogram`;
49+
50+
const response = await fetch(`${baseURL}/v1/ideogram-v3/generate`, {
51+
method: "POST",
52+
headers: {
53+
"Api-Key": ideogramApiKey,
54+
"Content-Type": "application/json",
55+
},
56+
body: JSON.stringify({
57+
prompt: "A serene landscape with mountains and a lake at sunset",
58+
model: "V_3",
59+
}),
60+
});
61+
62+
const result = await response.json();
63+
console.log(result);
64+
```
65+
66+
</TabItem>
67+
<TabItem label="Javascript (Workers)" icon="seti:javascript">
68+
69+
```js title="JavaScript (Workers)"
70+
import { useAIGateway, ProviderAuth } from "@cloudflare/ai-gateway";
71+
72+
export default {
73+
async fetch(request, env) {
74+
useAIGateway({ binding: env.AI, gateway: "test-gateway" });
75+
76+
const unifiedAuth = ProviderAuth.unifiedBilling();
77+
78+
const response = await fetch("https://api.ideogram.ai/v1/ideogram-v3/generate", {
79+
method: "POST",
80+
headers: {
81+
"Api-Key": unifiedAuth,
82+
"Content-Type": "application/json",
83+
},
84+
body: JSON.stringify({
85+
prompt: "A serene landscape with mountains and a lake at sunset",
86+
model: "V_3",
87+
}),
88+
});
89+
90+
const result = await response.json();
91+
return Response.json(result);
92+
},
93+
};
94+
```
95+
96+
</TabItem>
97+
</Tabs>

0 commit comments

Comments
 (0)