You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/ai-gateway/universal.mdx
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,6 +68,40 @@ ws.on("message", function incoming(message) {
68
68
});
69
69
```
70
70
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
+
typeEnv= {
86
+
AI:Ai;
87
+
};
88
+
89
+
exportdefault {
90
+
async fetch(request:Request, env:Env) {
91
+
returnenv.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
+
71
105
## Header configuration hierarchy
72
106
73
107
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