Skip to content

Commit 5157a92

Browse files
fixed invalid links
1 parent cc9270a commit 5157a92

File tree

6 files changed

+47
-38
lines changed

6 files changed

+47
-38
lines changed

src/content/changelog/ai-gateway/2025-01-26-worker-binding-methods.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ With the new AI Gateway binding methods, you can now:
1616

1717
- Send feedback and update metadata with `patchLog`.
1818
- Retrieve detailed log information using `getLog`.
19-
- Execute [universal requests](/ai-gateway/providers/universal/) to any AI Gateway provider with `run`.
19+
- Execute [universal requests](/ai-gateway/universal/) to any AI Gateway provider with `run`.
2020

2121
For example, to send feedback and update metadata using `patchLog`:
2222

src/content/changelog/ai-gateway/2025-02-05-aig-request-handling.mdx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ date: 2025-02-06T11:00:00Z
88

99
AI Gateway adds additional ways to handle requests - [Request Timeouts](/ai-gateway/configuration/request-handling/#request-timeouts) and [Request Retries](/ai-gateway/configuration/request-handling/#request-retries), making it easier to keep your applications responsive and reliable.
1010

11-
Timeouts and retries can be used on both the [Universal Endpoint](/ai-gateway/providers/universal) or directly to a [supported provider](/ai-gateway/providers/).
11+
Timeouts and retries can be used on both the [Universal Endpoint](/ai-gateway/universal) or directly to a [supported provider](/ai-gateway/providers/).
1212

1313
**Request timeouts**
14-
A [request timeout](/ai-gateway/configuration/request-handling/#request-timeouts) allows you to trigger [fallbacks](/ai-gateway/configuration/fallbacks/) or a retry if a provider takes too long to respond.
14+
A [request timeout](/ai-gateway/configuration/request-handling/#request-timeouts) allows you to trigger [fallbacks](/ai-gateway/configuration/fallbacks/) or a retry if a provider takes too long to respond.
1515

1616
To set a request timeout directly to a provider, add a `cf-aig-request-timeout` header.
1717

@@ -22,10 +22,12 @@ curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/workers-ai/@
2222
--header 'cf-aig-request-timeout: 5000'
2323
--data '{"prompt": "What is Cloudflare?"}'
2424
```
25+
2526
**Request retries**
2627
A [request retry](/ai-gateway/configuration/request-handling/#request-retries) automatically retries failed requests, so you can recover from temporary issues without intervening.
2728

2829
To set up request retries directly to a provider, add the following headers:
30+
2931
- cf-aig-max-attempts (number)
3032
- cf-aig-retry-delay (number)
31-
- cf-aig-backoff ("constant" | "linear" | "exponential)
33+
- cf-aig-backoff ("constant" | "linear" | "exponential)

src/content/docs/ai-gateway/configuration/fallbacks.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ sidebar:
77

88
import { Render } from "~/components";
99

10-
Specify model or provider fallbacks with your [Universal endpoint](/ai-gateway/providers/universal/) to handle request failures and ensure reliability.
10+
Specify model or provider fallbacks with your [Universal endpoint](/ai-gateway/universal/) to handle request failures and ensure reliability.
1111

1212
Cloudflare can trigger your fallback provider in response to [request errors](#request-failures) or [predetermined request timeouts](/ai-gateway/configuration/request-handling#request-timeouts). The [response header `cf-aig-step`](#response-headercf-aig-step) indicates which step successfully processed the request.
1313

@@ -38,7 +38,7 @@ You can add as many fallbacks as you need, just by adding another object in the
3838

3939
## Response header(cf-aig-step)
4040

41-
When using the [Universal endpoint](/ai-gateway/providers/universal/) with fallbacks, the response header `cf-aig-step` indicates which model successfully processed the request by returning the step number. This header provides visibility into whether a fallback was triggered and which model ultimately processed the response.
41+
When using the [Universal endpoint](/ai-gateway/universal/) with fallbacks, the response header `cf-aig-step` indicates which model successfully processed the request by returning the step number. This header provides visibility into whether a fallback was triggered and which model ultimately processed the response.
4242

4343
- `cf-aig-step:0` – The first (primary) model was used successfully.
4444
- `cf-aig-step:1` – The request fell back to the second model.

src/content/docs/ai-gateway/configuration/request-handling.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ A timeout is set in milliseconds. Additionally, the timeout is based on when the
2828

2929
#### Universal Endpoint
3030

31-
If set on a [Universal Endpoint](/ai-gateway/providers/universal/), a request timeout specifies the timeout duration for requests and triggers a fallback.
31+
If set on a [Universal Endpoint](/ai-gateway/universal/), a request timeout specifies the timeout duration for requests and triggers a fallback.
3232

3333
For a Universal Endpoint, configure the timeout value by setting a `requestTimeout` property within the provider-specific `config` object. Each provider can have a different `requestTimeout` value for granular customization.
3434

@@ -123,7 +123,7 @@ On the final retry attempt, your gateway will wait until the request completes,
123123

124124
#### Universal endpoint
125125

126-
If set on a [Universal Endpoint](/ai-gateway/providers/universal/), a request retry will automatically retry failed requests up to five times before triggering any configured fallbacks.
126+
If set on a [Universal Endpoint](/ai-gateway/universal/), a request retry will automatically retry failed requests up to five times before triggering any configured fallbacks.
127127

128128
For a Universal Endpoint, configure the retry settings with the following properties in the provider-specific `config`:
129129

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ AI Gateway supports a variety of headers to help you configure, customize, and m
1616
Settings in AI Gateway can be configured at three levels: **Provider**, **Request**, and **Gateway**. Since the same settings can be configured in multiple locations, the following hierarchy determines which value is applied:
1717

1818
1. **Provider-level headers**:
19-
Relevant only when using the [Universal Endpoint](/ai-gateway/providers/universal/), these headers take precedence over all other configurations.
19+
Relevant only when using the [Universal Endpoint](/ai-gateway/universal/), these headers take precedence over all other configurations.
2020
2. **Request-level headers**:
2121
Apply if no provider-level headers are set.
2222
3. **Gateway-level settings**:

src/content/docs/ai-gateway/integrations/worker-binding-methods.mdx

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ This configuration sets up the AI binding accessible in your Worker code as `env
3434
To perform an inference task using Workers AI and an AI Gateway, you can use the following code:
3535

3636
```typescript title="src/index.ts"
37-
const resp = await env.AI.run("@cf/meta/llama-3.1-8b-instruct", {
38-
prompt: "tell me a joke"
39-
}, {
40-
gateway: {
41-
id: "my-gateway"
42-
}
43-
});
37+
const resp = await env.AI.run(
38+
"@cf/meta/llama-3.1-8b-instruct",
39+
{
40+
prompt: "tell me a joke",
41+
},
42+
{
43+
gateway: {
44+
id: "my-gateway",
45+
},
46+
},
47+
);
4448
```
4549

4650
Additionally, you can access the latest request log ID with:
@@ -64,12 +68,12 @@ Once you have the gateway instance, you can use the following methods:
6468
The `patchLog` method allows you to send feedback, score, and metadata for a specific log ID. All object properties are optional, so you can include any combination of the parameters:
6569

6670
```typescript
67-
gateway.patchLog('my-log-id', {
68-
feedback: 1,
69-
score: 100,
70-
metadata: {
71-
user: "123"
72-
}
71+
gateway.patchLog("my-log-id", {
72+
feedback: 1,
73+
score: 100,
74+
metadata: {
75+
user: "123",
76+
},
7377
});
7478
```
7579

@@ -97,7 +101,7 @@ const baseUrl = await gateway.getUrl();
97101
// Output: https://gateway.ai.cloudflare.com/v1/my-account-id/my-gateway/
98102

99103
// Get a provider-specific URL
100-
const openaiUrl = await gateway.getUrl('openai');
104+
const openaiUrl = await gateway.getUrl("openai");
101105
// Output: https://gateway.ai.cloudflare.com/v1/my-account-id/my-gateway/openai
102106
```
103107

@@ -110,54 +114,57 @@ const openaiUrl = await gateway.getUrl('openai');
110114
The `getUrl` method is particularly useful for integrating with popular AI SDKs:
111115

112116
**OpenAI SDK:**
117+
113118
```typescript
114119
import OpenAI from "openai";
115120

116121
const openai = new OpenAI({
117-
apiKey: "my api key", // defaults to process.env["OPENAI_API_KEY"]
118-
baseURL: await env.AI.gateway('my-gateway').getUrl('openai'),
122+
apiKey: "my api key", // defaults to process.env["OPENAI_API_KEY"]
123+
baseURL: await env.AI.gateway("my-gateway").getUrl("openai"),
119124
});
120125
```
121126

122127
**Vercel AI SDK with OpenAI:**
128+
123129
```typescript
124130
import { createOpenAI } from "@ai-sdk/openai";
125131

126132
const openai = createOpenAI({
127-
baseURL: await env.AI.gateway('my-gateway').getUrl('openai'),
133+
baseURL: await env.AI.gateway("my-gateway").getUrl("openai"),
128134
});
129135
```
130136

131137
**Vercel AI SDK with Anthropic:**
138+
132139
```typescript
133140
import { createAnthropic } from "@ai-sdk/anthropic";
134141

135142
const anthropic = createAnthropic({
136-
baseURL: await env.AI.gateway('my-gateway').getUrl('anthropic'),
143+
baseURL: await env.AI.gateway("my-gateway").getUrl("anthropic"),
137144
});
138145
```
139146

140147
### 3.4. `run`: Universal Requests
141148

142149
The `run` method allows you to execute universal requests. Users can pass either a single universal request object or an array of them. This method supports all AI Gateway providers.
143150

144-
Refer to the [Universal endpoint documentation](/ai-gateway/providers/universal/) for details about the available inputs.
151+
Refer to the [Universal endpoint documentation](/ai-gateway/universal/) for details about the available inputs.
145152

146153
```typescript
147154
const resp = await gateway.run({
148-
provider: "workers-ai",
149-
endpoint: "@cf/meta/llama-3.1-8b-instruct",
150-
headers: {
151-
authorization: "Bearer my-api-token"
152-
},
153-
query: {
154-
prompt: "tell me a joke"
155-
}
155+
provider: "workers-ai",
156+
endpoint: "@cf/meta/llama-3.1-8b-instruct",
157+
headers: {
158+
authorization: "Bearer my-api-token",
159+
},
160+
query: {
161+
prompt: "tell me a joke",
162+
},
156163
});
157164
```
158165

159166
- **Returns**: `Promise<Response>`
160-
- **Example Use Case**: Perform a [universal request](/ai-gateway/providers/universal/) to any supported provider.
167+
- **Example Use Case**: Perform a [universal request](/ai-gateway/universal/) to any supported provider.
161168

162169
## Conclusion
163170

@@ -168,4 +175,4 @@ With these AI Gateway binding methods, you can now:
168175
- Get gateway URLs for direct API access with `getUrl`, making it easy to integrate with popular AI SDKs.
169176
- Execute universal requests to any AI Gateway provider with `run`.
170177

171-
These methods offer greater flexibility and control over your AI integrations, empowering you to build more sophisticated applications on the Cloudflare Workers platform.
178+
These methods offer greater flexibility and control over your AI integrations, empowering you to build more sophisticated applications on the Cloudflare Workers platform.

0 commit comments

Comments
 (0)