Skip to content

Commit a0a725f

Browse files
authored
feat (ai): export createGateway (#8535)
## Background `createGateway` should be exported so people do not have to install the gateway package directly (which could lead to version conflicts and confusion). ## Summary - export `createGateway` - update gateway provider docs ## Related Issues Follow up from #8507
1 parent c37bc3b commit a0a725f

File tree

3 files changed

+15
-29
lines changed

3 files changed

+15
-29
lines changed

.changeset/seven-rules-fetch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'ai': patch
3+
---
4+
5+
feat (ai): export createGateway

content/providers/01-ai-sdk-providers/00-ai-gateway.mdx

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,7 @@ The [AI Gateway](https://vercel.com/docs/ai-gateway) provider connects you to mo
1818

1919
## Setup
2020

21-
The AI Gateway provider is available in the `@ai-sdk/gateway` module. You can install it with
22-
23-
<Tabs items={['pnpm', 'npm', 'yarn', 'bun']}>
24-
<Tab>
25-
<Snippet text="pnpm add @ai-sdk/gateway" dark />
26-
</Tab>
27-
<Tab>
28-
<Snippet text="npm install @ai-sdk/gateway" dark />
29-
</Tab>
30-
<Tab>
31-
<Snippet text="yarn add @ai-sdk/gateway" dark />
32-
</Tab>
33-
34-
<Tab>
35-
<Snippet text="bun add @ai-sdk/gateway" dark />
36-
</Tab>
37-
</Tabs>
21+
The Vercel AI Gateway provider is part of the AI SDK.
3822

3923
## Basic Usage
4024

@@ -52,8 +36,7 @@ const { text } = await generateText({
5236

5337
```ts
5438
// use provider instance
55-
import { generateText } from 'ai';
56-
import { gateway } from '@ai-sdk/gateway';
39+
import { generateText, gateway } from 'ai';
5740

5841
const { text } = await generateText({
5942
model: gateway('openai/gpt-5'),
@@ -65,10 +48,10 @@ The AI SDK automatically uses the AI Gateway when you pass a model string in the
6548

6649
## Provider Instance
6750

68-
You can also import the default provider instance `gateway` from `@ai-sdk/gateway`:
51+
You can also import the default provider instance `gateway` from `ai`:
6952

7053
```ts
71-
import { gateway } from '@ai-sdk/gateway';
54+
import { gateway } from 'ai';
7255
```
7356

7457
You may want to create a custom provider instance when you need to:
@@ -78,10 +61,10 @@ You may want to create a custom provider instance when you need to:
7861
- Wrap the provider with [middleware](/docs/ai-sdk-core/middleware)
7962
- Use different settings for different parts of your application
8063

81-
To create a custom provider instance, import `createGateway` from `@ai-sdk/gateway`:
64+
To create a custom provider instance, import `createGateway` from `ai`:
8265

8366
```ts
84-
import { createGateway } from '@ai-sdk/gateway';
67+
import { createGateway } from 'ai';
8568

8669
const gateway = createGateway({
8770
apiKey: process.env.AI_GATEWAY_API_KEY ?? '',
@@ -129,7 +112,7 @@ AI_GATEWAY_API_KEY=your_api_key_here
129112
Or pass it directly to the provider:
130113

131114
```ts
132-
import { createGateway } from '@ai-sdk/gateway';
115+
import { createGateway } from 'ai';
133116

134117
const gateway = createGateway({
135118
apiKey: 'your_api_key_here',
@@ -191,8 +174,7 @@ For the complete list of available models, see the [AI Gateway documentation](ht
191174
You can discover available models programmatically:
192175

193176
```ts
194-
import { gateway } from '@ai-sdk/gateway';
195-
import { generateText } from 'ai';
177+
import { gateway, generateText } from 'ai';
196178

197179
const availableModels = await gateway.getAvailableModels();
198180

@@ -300,8 +282,7 @@ const { text } = await generateText({
300282

301283
```ts
302284
// with provider instance
303-
import { generateText } from 'ai';
304-
import { gateway } from '@ai-sdk/gateway';
285+
import { gateway, generateText } from 'ai';
305286

306287
const { text } = await generateText({
307288
model: gateway('anthropic/claude-sonnet-4'),

packages/ai/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// re-exports:
2-
export { gateway } from '@ai-sdk/gateway';
2+
export { gateway, createGateway } from '@ai-sdk/gateway';
33
export {
44
asSchema,
55
createIdGenerator,

0 commit comments

Comments
 (0)