Skip to content

Commit b944a01

Browse files
committed
Add binding example to AI Gateway universal page
1 parent edb40dd commit b944a01

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/content/docs/ai-gateway/universal.mdx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,40 @@ ws.on("message", function incoming(message) {
6868
});
6969
```
7070

71+
## Workers Binding example
72+
73+
import { WranglerConfig } from "~/components";
74+
75+
<WranglerConfig>
76+
77+
```toml title="wrangler.toml"
78+
[ai]
79+
binding = "AI"
80+
```
81+
82+
</WranglerConfig>
83+
84+
```typescript title="src/index.ts"
85+
type Env = {
86+
AI: Ai;
87+
};
88+
89+
export default {
90+
async fetch(request: Request, env: Env) {
91+
return env.AI.gateway('my-gateway').run({
92+
provider: "workers-ai",
93+
endpoint: "@cf/meta/llama-3.1-8b-instruct",
94+
headers: {
95+
authorization: "Bearer my-api-token",
96+
},
97+
query: {
98+
prompt: "tell me a joke",
99+
},
100+
});
101+
},
102+
};
103+
```
104+
71105
## Header configuration hierarchy
72106

73107
The Universal Endpoint allows you to set fallback models or providers and customize headers for each provider or request. You can configure headers at three levels:

0 commit comments

Comments
 (0)