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/agents/index.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,7 +56,7 @@ We built the `agents-sdk` with a few things in mind:
56
56
57
57
Agents built with `agents-sdk` can be deployed directly to Cloudflare and run on top of [Durable Objects](/durable-objects/) — which you can think of as stateful micro-servers that can scale to tens of millions — and are able to run wherever they need to. Run your Agents close to a user for low-latency interactivity, close to your data for throughput, and/or anywhere in between.
This guide provides an overview of how to use the latest Cloudflare Workers AI Gateway binding methods. You will learn how to set up an AI Gateway binding, access new methods, and integrate them into your Workers.
10
10
11
-
## Prerequisites
12
-
13
-
- Install and use the `@cloudflare/workers-types` library, version `4.20250124.3` or above.
14
-
15
11
## 1. Add an AI Binding to your Worker
16
12
17
13
To connect your Worker to Workers AI, add the following to your [Wrangler configuration file](/workers/wrangler/configuration/):
@@ -37,7 +33,7 @@ To perform an inference task using Workers AI and an AI Gateway, you can use the
@@ -65,9 +61,9 @@ The `patchLog` method allows you to send feedback, score, and metadata for a spe
65
61
66
62
```typescript
67
63
gateway.patchLog('my-log-id', {
68
-
feedback: 1,
69
-
score: 100,
70
-
metadata: {
64
+
feedback: 1,
65
+
score: 100,
66
+
metadata: {
71
67
user: "123"
72
68
}
73
69
});
@@ -78,7 +74,7 @@ gateway.patchLog('my-log-id', {
78
74
79
75
### 3.2. `getLog`: Read Log Details
80
76
81
-
The `getLog` method retrieves details of a specific log ID. It returns an object of type `Promise<AiGatewayLog>`. You can import the `AiGatewayLog` type from the `@cloudflare/workers-types` library.
77
+
The `getLog` method retrieves details of a specific log ID. It returns an object of type `Promise<AiGatewayLog>`. If this type is missing, ensure you have run [`wrangler types`](/workers/languages/typescript/#generate-types)
82
78
83
79
```typescript
84
80
const log =awaitgateway.getLog("my-log-id");
@@ -95,12 +91,12 @@ Refer to the [Universal endpoint documentation](/ai-gateway/providers/universal/
95
91
96
92
```typescript
97
93
const resp =awaitgateway.run({
98
-
provider: "workers-ai",
99
-
endpoint: "@cf/meta/llama-3.1-8b-instruct",
100
-
headers: {
94
+
provider: "workers-ai",
95
+
endpoint: "@cf/meta/llama-3.1-8b-instruct",
96
+
headers: {
101
97
authorization: "Bearer my-api-token"
102
-
},
103
-
query: {
98
+
},
99
+
query: {
104
100
prompt: "tell me a joke"
105
101
}
106
102
});
@@ -118,4 +114,3 @@ With the new AI Gateway binding methods, you can now:
118
114
- Execute universal requests to any AI Gateway provider with `run`.
119
115
120
116
These methods offer greater flexibility and control over your AI integrations, empowering you to build more sophisticated applications on the Cloudflare Workers platform.
Copy file name to clipboardExpand all lines: src/content/docs/d1/worker-api/index.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ Refer to the relevant sections for the API documentation.
18
18
19
19
## TypeScript support
20
20
21
-
D1 Worker Bindings API is fully-typed via the [`@cloudflare/workers-types`](/workers/languages/typescript/#typescript) package, and also supports [generic types](https://www.typescriptlang.org/docs/handbook/2/generics.html#generic-types) as part of its TypeScript API. A generic type allows you to provide an optional `type parameter` so that a function understands the type of the data it is handling.
21
+
D1 Worker Bindings API is fully-typed via the types generated by running [`wrangler types`](/workers/languages/typescript/#typescript) package, and also supports [generic types](https://www.typescriptlang.org/docs/handbook/2/generics.html#generic-types) as part of its TypeScript API. A generic type allows you to provide an optional `type parameter` so that a function understands the type of the data it is handling.
22
22
23
23
When using the query statement methods [`D1PreparedStatement::run`](/d1/worker-api/prepared-statements/#run), [`D1PreparedStatement::raw`](/d1/worker-api/prepared-statements/#raw) and [`D1PreparedStatement::first`](/d1/worker-api/prepared-statements/#first), you can provide a type representing each database row. D1's API will [return the result object](/d1/worker-api/return-object/#d1result) with the correct type.
Copy file name to clipboardExpand all lines: src/content/docs/pages/framework-guides/deploy-a-nuxt-site.mdx
+1-7Lines changed: 1 addition & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -121,17 +121,11 @@ In order to access bindings in a deployed application, you will need to [configu
121
121
122
122
### Add bindings to TypeScript projects
123
123
124
-
To get proper type support, you need to create a new `env.d.ts` file in the root of your project and declare a [binding](/pages/functions/bindings/).
124
+
To get proper type support, you need to create a new `env.d.ts` file in the root of your project and declare a [binding](/pages/functions/bindings/). Make sure you have generated Cloudflare runtime types by running [`wrangler types`](/pages/functions/typescript/).
125
125
126
126
The following is an example of adding a `KVNamespace` binding:
Copy file name to clipboardExpand all lines: src/content/docs/pages/framework-guides/deploy-an-astro-site.mdx
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -109,12 +109,11 @@ Use bindings in Astro components and API routes by using `context.locals` from [
109
109
110
110
Refer to the following example of how to access a KV namespace with TypeScript.
111
111
112
-
First, you need to define Cloudflare runtime and KV type by updating the `env.d.ts`:
112
+
First, you need to define Cloudflare runtime and KV type by updating the `env.d.ts`. Make sure you have generated Cloudflare runtime types by running [`wrangler types`](/pages/functions/typescript/).
Copy file name to clipboardExpand all lines: src/content/docs/pages/framework-guides/nextjs/ssr/bindings.mdx
+1-26Lines changed: 1 addition & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,32 +30,7 @@ Add bindings to your Pages project by adding them to your [Wrangler configuratio
30
30
31
31
## TypeScript type declarations for bindings
32
32
33
-
To ensure that the `env` object from `getRequestContext().env` above has accurate TypeScript types, install [`@cloudflare/workers-types`](https://www.npmjs.com/package/@cloudflare/workers-types) and create a [TypeScript declaration file](https://www.typescriptlang.org/docs/handbook/2/type-declarations.html).
34
-
35
-
Install Workers Types:
36
-
37
-
```sh
38
-
npm install --save-dev @cloudflare/workers-types
39
-
```
40
-
41
-
Add Workers Types to your `tsconfig.json` file, replacing the date below with your project's [compatibility date](/workers/configuration/compatibility-dates/):
42
-
43
-
```diff title="tsconfig.json"
44
-
"types": [
45
-
+ "@cloudflare/workers-types/2024-07-29"
46
-
]
47
-
```
48
-
49
-
Create an `env.d.ts` file in the root directory of your Next.js app, and explicitly declare the type of each binding:
50
-
51
-
```ts title="env.d.ts"
52
-
interfaceCloudflareEnv {
53
-
MY_KV_1:KVNamespace;
54
-
MY_KV_2:KVNamespace;
55
-
MY_R2:R2Bucket;
56
-
MY_DO:DurableObjectNamespace;
57
-
}
58
-
```
33
+
To ensure that the `env` object from `getRequestContext().env` above has accurate TypeScript types, make sure you have generated types by running [`wrangler types`](/workers/languages/typescript/#generate-types) and followed the setup steps.
Copy file name to clipboardExpand all lines: src/content/docs/vectorize/reference/client-api.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -220,4 +220,4 @@ Refer to the [bindings documentation](/workers/wrangler/configuration/#vectorize
220
220
221
221
New Workers projects created via `npm create cloudflare@latest` automatically include the relevant TypeScript types for Vectorize.
222
222
223
-
Older projects, or non-Workers projects looking to use Vectorize's [REST API](https://developers.cloudflare.com/api/resources/vectorize/subresources/indexes/methods/list/) in a TypeScript project, should ensure `@cloudflare/workers-types` version `4.20230922.0` or later is installed.
223
+
If you have an older project, or a non-Workers projects looking to use Vectorize's [REST API](https://developers.cloudflare.com/api/resources/vectorize/subresources/indexes/methods/list/) in a TypeScript project, you should ensure you have a compatibility date later than `2023-09-22` and that you have generated types by running [`wrangler types`](/workers/languages/typescript/#generate-types).
Invalid or incorrectly-named keys in the `cf` object will be silently ignored. Consider using TypeScript and [`@cloudflare/workers-types`](https://www.npmjs.com/package/@cloudflare/workers-types) to ensure proper use of the `cf` object.
102
+
Invalid or incorrectly-named keys in the `cf` object will be silently ignored. Consider using TypeScript and generating types by running [`wrangler types`](/workers/languages/typescript/#generate-types) to ensure proper use of the `cf` object.
Copy file name to clipboardExpand all lines: src/content/docs/workers/runtime-apis/rpc/typescript.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ description: How TypeScript types for your Worker or Durable Object's RPC
11
11
12
12
---
13
13
14
-
The [`@cloudflare/workers-types`](https://www.npmjs.com/package/@cloudflare/workers-types)package provides the `Service` and `DurableObjectNamespace` types, each of which accepts a single type parameter for the server-side [`WorkerEntrypoint`](/workers/runtime-apis/bindings/service-bindings/rpc) or [`DurableObject`](/durable-objects/best-practices/create-durable-object-stubs-and-send-requests/#call-rpc-methods) types.
14
+
The types generated by running [`wrangler types`](/workers/languages/typescript/#generate-types)provide the `Service` and `DurableObjectNamespace` types, each of which accepts a single type parameter for the server-side [`WorkerEntrypoint`](/workers/runtime-apis/bindings/service-bindings/rpc) or [`DurableObject`](/durable-objects/best-practices/create-durable-object-stubs-and-send-requests/#call-rpc-methods) types.
15
15
16
16
Using higher-order types, we automatically generate client-side stub types (e.g., forcing all methods to be async).
0 commit comments