Skip to content

Commit 3fe85b7

Browse files
committed
Add Universal endpoint
1 parent 3d6a32b commit 3fe85b7

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/content/docs/ai-gateway/chat-completion.mdx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,34 @@ curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/comp
6464

6565
### Universal provider
6666

67-
TBD
67+
You can also use this pattern with a [Universal Endpoint](/ai-gateway/universal/).
68+
69+
```ts title="index.ts"
70+
export interface Env {
71+
AI: Ai;
72+
}
73+
74+
export default {
75+
async fetch(request: Request, env: Env) {
76+
return env.AI.gateway("default").run({
77+
provider: "compat",
78+
endpoint: "chat/completions",
79+
headers: {
80+
authorization: "Bearer ",
81+
},
82+
query: {
83+
model: "google-ai-studio/gemini-2.0-flash",
84+
messages: [
85+
{
86+
role: "user",
87+
content: "What is Cloudflare?",
88+
},
89+
],
90+
},
91+
});
92+
},
93+
};
94+
```
6895

6996
## Supported Providers
7097

0 commit comments

Comments
 (0)