@runpod/ai-sdk-provider 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +275 -198
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,198 +1,275 @@
|
|
|
1
|
-
# Runpod AI SDK Provider
|
|
2
|
-
|
|
3
|
-
The **Runpod provider** for the [AI SDK](https://ai-sdk.dev/docs) contains language model and image generation support for [Runpod's](https://runpod.io) public endpoints.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
# npm
|
|
9
|
-
npm install @runpod/ai-sdk-provider
|
|
10
|
-
|
|
11
|
-
# pnpm
|
|
12
|
-
pnpm add @runpod/ai-sdk-provider
|
|
13
|
-
|
|
14
|
-
# yarn
|
|
15
|
-
yarn add @runpod/ai-sdk-provider
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Setup
|
|
19
|
-
|
|
20
|
-
The Runpod provider requires a Runpod API key. You can obtain one from the [Runpod console](https://console.runpod.io/user/settings) under "API Keys".
|
|
21
|
-
|
|
22
|
-
### Environment Variable
|
|
23
|
-
|
|
24
|
-
Set your API key as an environment variable:
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
export RUNPOD_API_KEY="your-api-key-here"
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### Provider Instance
|
|
31
|
-
|
|
32
|
-
Import the provider:
|
|
33
|
-
|
|
34
|
-
```ts
|
|
35
|
-
import { runpod } from '@runpod/ai-sdk-provider';
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## Supported Models
|
|
39
|
-
|
|
40
|
-
### Language Models
|
|
41
|
-
|
|
42
|
-
| Model ID | Description |
|
|
43
|
-
| -------------------------------------- | ------------------------------------------------------------------- |
|
|
44
|
-
| `deep-cogito/deep-cogito-v2-llama-70b` | 70B parameter general-purpose LLM with advanced reasoning |
|
|
45
|
-
| `qwen/qwen3-32b-awq` | 32B parameter multilingual model with strong reasoning capabilities |
|
|
46
|
-
|
|
47
|
-
### Image Models
|
|
48
|
-
|
|
49
|
-
| Model ID | Description | Supported Aspect Ratios |
|
|
50
|
-
| -------------------------------------- | ------------------------------- | ----------------------- |
|
|
51
|
-
| `qwen/qwen-image` | Text-to-image generation | 1:1, 4:3, 3:4 |
|
|
52
|
-
| `bytedance/seedream-3.0` | Advanced text-to-image model | 1:1, 4:3, 3:4 |
|
|
53
|
-
| `black-forest-labs/flux-1-kontext-dev` | Context-aware image generation | 1:1, 4:3, 3:4 |
|
|
54
|
-
| `black-forest-labs/flux-1-schnell` | Fast image generation (4 steps) | 1:1, 4:3, 3:4 |
|
|
55
|
-
| `black-forest-labs/flux-1-dev` | High-quality image generation | 1:1, 4:3, 3:4 |
|
|
56
|
-
|
|
57
|
-
##
|
|
58
|
-
|
|
59
|
-
### Basic
|
|
60
|
-
|
|
61
|
-
```ts
|
|
62
|
-
import { runpod } from '@runpod/ai-sdk-provider';
|
|
63
|
-
import { generateText } from 'ai';
|
|
64
|
-
|
|
65
|
-
const { text } = await generateText({
|
|
66
|
-
model: runpod('deep-cogito/deep-cogito-v2-llama-70b'),
|
|
67
|
-
prompt: 'Write a Python function that sorts a list:',
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
### Chat Conversations
|
|
78
|
-
|
|
79
|
-
```ts
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
### Structured Output
|
|
118
|
-
|
|
119
|
-
```ts
|
|
120
|
-
import {
|
|
121
|
-
import {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
1
|
+
# Runpod AI SDK Provider
|
|
2
|
+
|
|
3
|
+
The **Runpod provider** for the [AI SDK](https://ai-sdk.dev/docs) contains language model and image generation support for [Runpod's](https://runpod.io) public endpoints.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# npm
|
|
9
|
+
npm install @runpod/ai-sdk-provider
|
|
10
|
+
|
|
11
|
+
# pnpm
|
|
12
|
+
pnpm add @runpod/ai-sdk-provider
|
|
13
|
+
|
|
14
|
+
# yarn
|
|
15
|
+
yarn add @runpod/ai-sdk-provider
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Setup
|
|
19
|
+
|
|
20
|
+
The Runpod provider requires a Runpod API key. You can obtain one from the [Runpod console](https://console.runpod.io/user/settings) under "API Keys".
|
|
21
|
+
|
|
22
|
+
### Environment Variable
|
|
23
|
+
|
|
24
|
+
Set your API key as an environment variable:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
export RUNPOD_API_KEY="your-api-key-here"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Provider Instance
|
|
31
|
+
|
|
32
|
+
Import the provider:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { runpod } from '@runpod/ai-sdk-provider';
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Supported Models
|
|
39
|
+
|
|
40
|
+
### Language Models
|
|
41
|
+
|
|
42
|
+
| Model ID | Description |
|
|
43
|
+
| -------------------------------------- | ------------------------------------------------------------------- |
|
|
44
|
+
| `deep-cogito/deep-cogito-v2-llama-70b` | 70B parameter general-purpose LLM with advanced reasoning |
|
|
45
|
+
| `qwen/qwen3-32b-awq` | 32B parameter multilingual model with strong reasoning capabilities |
|
|
46
|
+
|
|
47
|
+
### Image Models
|
|
48
|
+
|
|
49
|
+
| Model ID | Description | Supported Aspect Ratios |
|
|
50
|
+
| -------------------------------------- | ------------------------------- | ----------------------- |
|
|
51
|
+
| `qwen/qwen-image` | Text-to-image generation | 1:1, 4:3, 3:4 |
|
|
52
|
+
| `bytedance/seedream-3.0` | Advanced text-to-image model | 1:1, 4:3, 3:4 |
|
|
53
|
+
| `black-forest-labs/flux-1-kontext-dev` | Context-aware image generation | 1:1, 4:3, 3:4 |
|
|
54
|
+
| `black-forest-labs/flux-1-schnell` | Fast image generation (4 steps) | 1:1, 4:3, 3:4 |
|
|
55
|
+
| `black-forest-labs/flux-1-dev` | High-quality image generation | 1:1, 4:3, 3:4 |
|
|
56
|
+
|
|
57
|
+
## Text Generation
|
|
58
|
+
|
|
59
|
+
### Basic Usage
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { runpod } from '@runpod/ai-sdk-provider';
|
|
63
|
+
import { generateText } from 'ai';
|
|
64
|
+
|
|
65
|
+
const { text } = await generateText({
|
|
66
|
+
model: runpod('deep-cogito/deep-cogito-v2-llama-70b'),
|
|
67
|
+
prompt: 'Write a Python function that sorts a list:',
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Returns:**
|
|
72
|
+
|
|
73
|
+
- `text` - Generated text string
|
|
74
|
+
- `finishReason` - Why generation stopped ('stop', 'length', etc.)
|
|
75
|
+
- `usage` - Token usage information (prompt, completion, total tokens)
|
|
76
|
+
|
|
77
|
+
### Chat Conversations
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const { text } = await generateText({
|
|
81
|
+
model: runpod('deep-cogito/deep-cogito-v2-llama-70b'),
|
|
82
|
+
messages: [
|
|
83
|
+
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
84
|
+
{ role: 'user', content: 'What is the capital of France?' },
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Function Calling
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { generateText, tool } from 'ai';
|
|
93
|
+
import { z } from 'zod';
|
|
94
|
+
|
|
95
|
+
const { text, toolCalls } = await generateText({
|
|
96
|
+
model: runpod('deep-cogito/deep-cogito-v2-llama-70b'),
|
|
97
|
+
prompt: 'What is the weather like in San Francisco?',
|
|
98
|
+
tools: {
|
|
99
|
+
getWeather: tool({
|
|
100
|
+
description: 'Get weather information for a city',
|
|
101
|
+
parameters: z.object({
|
|
102
|
+
city: z.string().describe('The city name'),
|
|
103
|
+
}),
|
|
104
|
+
execute: async ({ city }) => {
|
|
105
|
+
return `The weather in ${city} is sunny.`;
|
|
106
|
+
},
|
|
107
|
+
}),
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Additional Returns:**
|
|
113
|
+
|
|
114
|
+
- `toolCalls` - Array of tool calls made by the model
|
|
115
|
+
- `toolResults` - Results from executed tools
|
|
116
|
+
|
|
117
|
+
### Structured Output
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { generateObject } from 'ai';
|
|
121
|
+
import { z } from 'zod';
|
|
122
|
+
|
|
123
|
+
const { object } = await generateObject({
|
|
124
|
+
model: runpod('qwen/qwen3-32b-awq'),
|
|
125
|
+
schema: z.object({
|
|
126
|
+
recipe: z.object({
|
|
127
|
+
name: z.string(),
|
|
128
|
+
ingredients: z.array(z.string()),
|
|
129
|
+
steps: z.array(z.string()),
|
|
130
|
+
}),
|
|
131
|
+
}),
|
|
132
|
+
prompt: 'Generate a recipe for chocolate chip cookies.',
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Returns:**
|
|
137
|
+
|
|
138
|
+
- `object` - Parsed object matching your schema
|
|
139
|
+
- `usage` - Token usage information
|
|
140
|
+
|
|
141
|
+
### Streaming
|
|
142
|
+
|
|
143
|
+
**Note**: Streaming is not yet supported by Runpod's public endpoints. The team is working on implementing this feature.
|
|
144
|
+
|
|
145
|
+
## Image Generation
|
|
146
|
+
|
|
147
|
+
### Basic Usage
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import { runpod } from '@runpod/ai-sdk-provider';
|
|
151
|
+
import { experimental_generateImage as generateImage } from 'ai';
|
|
152
|
+
|
|
153
|
+
const { image } = await generateImage({
|
|
154
|
+
model: runpod.imageModel('qwen/qwen-image'),
|
|
155
|
+
prompt: 'A fashion-forward woman in Paris wearing a trench coat',
|
|
156
|
+
aspectRatio: '4:3',
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Returns:**
|
|
161
|
+
|
|
162
|
+
- `image.uint8Array` - Binary image data (efficient for processing/saving)
|
|
163
|
+
- `image.base64` - Base64 encoded string (for web display)
|
|
164
|
+
- `image.mediaType` - MIME type ('image/jpeg' or 'image/png')
|
|
165
|
+
- `warnings` - Array of any warnings about unsupported parameters
|
|
166
|
+
|
|
167
|
+
### Advanced Parameters
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
const { image } = await generateImage({
|
|
171
|
+
model: runpod.imageModel('bytedance/seedream-3.0'),
|
|
172
|
+
prompt: 'A sunset over mountains',
|
|
173
|
+
size: '1328x1328',
|
|
174
|
+
seed: 42,
|
|
175
|
+
providerOptions: {
|
|
176
|
+
runpod: {
|
|
177
|
+
negative_prompt: 'blurry, low quality',
|
|
178
|
+
enable_safety_checker: true,
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// Save to filesystem
|
|
184
|
+
import { writeFileSync } from 'fs';
|
|
185
|
+
writeFileSync('generated-image.jpg', image.uint8Array);
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Context-Aware Generation (Flux Kontext)
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
const { image } = await generateImage({
|
|
192
|
+
model: runpod.imageModel('black-forest-labs/flux-1-kontext-dev'),
|
|
193
|
+
prompt: 'Transform this into a cyberpunk style with neon lights',
|
|
194
|
+
aspectRatio: '1:1',
|
|
195
|
+
providerOptions: {
|
|
196
|
+
runpod: {
|
|
197
|
+
image: 'https://example.com/input-image.jpg', // Image URL
|
|
198
|
+
negative_prompt: 'blurry, distorted',
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// Alternative: Using base64 encoded image
|
|
204
|
+
const { image } = await generateImage({
|
|
205
|
+
model: runpod.imageModel('black-forest-labs/flux-1-kontext-dev'),
|
|
206
|
+
prompt: 'Make this image look like a painting',
|
|
207
|
+
aspectRatio: '4:3',
|
|
208
|
+
providerOptions: {
|
|
209
|
+
runpod: {
|
|
210
|
+
image: 'data:image/png;base64,iVBORw0KGgoAAAANS...', // Base64 data URI
|
|
211
|
+
negative_prompt: 'blurry, distorted',
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Advanced Configuration
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
// Full control over generation parameters
|
|
221
|
+
const { image } = await generateImage({
|
|
222
|
+
model: runpod.imageModel('black-forest-labs/flux-1-dev'),
|
|
223
|
+
prompt: 'A majestic dragon breathing fire in a medieval castle',
|
|
224
|
+
size: '1328x1328',
|
|
225
|
+
seed: 42, // For reproducible results
|
|
226
|
+
providerOptions: {
|
|
227
|
+
runpod: {
|
|
228
|
+
negative_prompt: 'blurry, low quality, distorted, ugly, bad anatomy',
|
|
229
|
+
enable_safety_checker: true,
|
|
230
|
+
num_inference_steps: 50, // Higher quality (default: 28)
|
|
231
|
+
guidance: 3.5, // Stronger prompt adherence (default: 2)
|
|
232
|
+
output_format: 'png', // High quality format
|
|
233
|
+
// Polling settings for long generations
|
|
234
|
+
maxPollAttempts: 30,
|
|
235
|
+
pollIntervalMillis: 4000,
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// Fast generation with minimal steps
|
|
241
|
+
const { image } = await generateImage({
|
|
242
|
+
model: runpod.imageModel('black-forest-labs/flux-1-schnell'),
|
|
243
|
+
prompt: 'A simple red apple',
|
|
244
|
+
aspectRatio: '1:1',
|
|
245
|
+
providerOptions: {
|
|
246
|
+
runpod: {
|
|
247
|
+
num_inference_steps: 2, // Even faster (default: 4)
|
|
248
|
+
guidance: 10, // Higher guidance for simple prompts
|
|
249
|
+
output_format: 'jpg', // Smaller file size
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Provider Options
|
|
256
|
+
|
|
257
|
+
| Option | Type | Default | Description |
|
|
258
|
+
| ----------------------- | --------- | ------- | ----------------------------------------------------------------------- |
|
|
259
|
+
| `negative_prompt` | `string` | `""` | Text describing what you don't want in the image |
|
|
260
|
+
| `enable_safety_checker` | `boolean` | `true` | Enable content safety filtering |
|
|
261
|
+
| `image` | `string` | - | Input image: URL or base64 data URI (required for Flux Kontext models) |
|
|
262
|
+
| `num_inference_steps` | `number` | Auto | Number of denoising steps (Flux: 4 for schnell, 28 for others) |
|
|
263
|
+
| `guidance` | `number` | Auto | Guidance scale for prompt adherence (Flux: 7 for schnell, 2 for others) |
|
|
264
|
+
| `output_format` | `string` | `"png"` | Output image format ("png" or "jpg") |
|
|
265
|
+
| `maxPollAttempts` | `number` | `60` | Maximum polling attempts for async generation |
|
|
266
|
+
| `pollIntervalMillis` | `number` | `5000` | Polling interval in milliseconds (5 seconds) |
|
|
267
|
+
|
|
268
|
+
**Note**: The provider uses strict validation for image parameters. Unsupported aspect ratios (like `16:9`, `9:16`, `3:2`, `2:3`) will throw an `InvalidArgumentError` with a clear message about supported alternatives.
|
|
269
|
+
|
|
270
|
+
## Links
|
|
271
|
+
|
|
272
|
+
- [Runpod](https://runpod.io) - Cloud platform for AI compute
|
|
273
|
+
- [Runpod Public Endpoints Documentation](https://docs.runpod.io/hub/public-endpoints)
|
|
274
|
+
- [AI SDK Documentation](https://ai-sdk.dev/docs)
|
|
275
|
+
- [GitHub Repository](https://github.com/runpod/ai-sdk-provider)
|