@ai-sdk/open-responses 2.0.6 → 2.0.9
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 +24 -0
- package/dist/index.js +1 -1
- package/docs/06-open-responses.mdx +164 -25
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @ai-sdk/open-responses
|
|
2
2
|
|
|
3
|
+
## 2.0.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [4be62c1]
|
|
8
|
+
- Updated dependencies [7805e4a]
|
|
9
|
+
- Updated dependencies [cd12954]
|
|
10
|
+
- @ai-sdk/provider-utils@5.0.9
|
|
11
|
+
|
|
12
|
+
## 2.0.8
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [e193290]
|
|
17
|
+
- @ai-sdk/provider-utils@5.0.8
|
|
18
|
+
|
|
19
|
+
## 2.0.7
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [0f93c57]
|
|
24
|
+
- @ai-sdk/provider@4.0.3
|
|
25
|
+
- @ai-sdk/provider-utils@5.0.7
|
|
26
|
+
|
|
3
27
|
## 2.0.6
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -5,26 +5,21 @@ description: Learn how to use the Open Responses provider for the AI SDK.
|
|
|
5
5
|
|
|
6
6
|
# Open Responses Provider
|
|
7
7
|
|
|
8
|
-
The [Open Responses](https://www.openresponses.org/) provider
|
|
8
|
+
The [Open Responses](https://www.openresponses.org/) provider connects AI SDK
|
|
9
|
+
Core to language model servers that implement an Open Responses-compatible
|
|
10
|
+
`POST` endpoint. Open Responses is an open specification based on the OpenAI
|
|
11
|
+
Responses API.
|
|
12
|
+
|
|
13
|
+
Use `@ai-sdk/open-responses` for third-party or self-hosted endpoints that
|
|
14
|
+
implement this protocol, such as LM Studio. If you call OpenAI directly and
|
|
15
|
+
need OpenAI-specific provider options or built-in tools, use the
|
|
16
|
+
[`@ai-sdk/openai` provider](/providers/ai-sdk-providers/openai) instead.
|
|
9
17
|
|
|
10
18
|
## Setup
|
|
11
19
|
|
|
12
20
|
The Open Responses provider is available in the `@ai-sdk/open-responses` module. You can install it with
|
|
13
21
|
|
|
14
|
-
<
|
|
15
|
-
<Tab>
|
|
16
|
-
<Snippet text="pnpm add @ai-sdk/open-responses" dark />
|
|
17
|
-
</Tab>
|
|
18
|
-
<Tab>
|
|
19
|
-
<Snippet text="npm install @ai-sdk/open-responses" dark />
|
|
20
|
-
</Tab>
|
|
21
|
-
<Tab>
|
|
22
|
-
<Snippet text="yarn add @ai-sdk/open-responses" dark />
|
|
23
|
-
</Tab>
|
|
24
|
-
<Tab>
|
|
25
|
-
<Snippet text="bun add @ai-sdk/open-responses" dark />
|
|
26
|
-
</Tab>
|
|
27
|
-
</Tabs>
|
|
22
|
+
<InstallPackages packages="@ai-sdk/open-responses" />
|
|
28
23
|
|
|
29
24
|
## Provider Instance
|
|
30
25
|
|
|
@@ -34,7 +29,7 @@ Create an Open Responses provider instance using `createOpenResponses`:
|
|
|
34
29
|
import { createOpenResponses } from '@ai-sdk/open-responses';
|
|
35
30
|
|
|
36
31
|
const openResponses = createOpenResponses({
|
|
37
|
-
name: '
|
|
32
|
+
name: 'lmstudio',
|
|
38
33
|
url: 'http://localhost:1234/v1/responses',
|
|
39
34
|
});
|
|
40
35
|
```
|
|
@@ -43,17 +38,19 @@ The `name` and `url` options are required:
|
|
|
43
38
|
|
|
44
39
|
- **name** _string_
|
|
45
40
|
|
|
46
|
-
Provider name. Used
|
|
41
|
+
Provider name. Used in the model's provider identifier and as the key for
|
|
42
|
+
provider options.
|
|
47
43
|
|
|
48
44
|
- **url** _string_
|
|
49
45
|
|
|
50
|
-
URL for the Open Responses API POST endpoint.
|
|
46
|
+
Full URL for the Open Responses API `POST` endpoint. Pass the endpoint URL,
|
|
47
|
+
such as `http://localhost:1234/v1/responses`, not only its base URL.
|
|
51
48
|
|
|
52
49
|
You can use the following optional settings to customize the Open Responses provider instance:
|
|
53
50
|
|
|
54
51
|
- **apiKey** _string_
|
|
55
52
|
|
|
56
|
-
API key that is
|
|
53
|
+
API key that is sent as a bearer token in the `Authorization` header.
|
|
57
54
|
|
|
58
55
|
- **headers** _Record<string,string>_
|
|
59
56
|
|
|
@@ -64,36 +61,178 @@ You can use the following optional settings to customize the Open Responses prov
|
|
|
64
61
|
Custom [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) implementation.
|
|
65
62
|
Defaults to the global `fetch` function.
|
|
66
63
|
|
|
64
|
+
### Endpoint Examples
|
|
65
|
+
|
|
66
|
+
For a local LM Studio server that does not require authentication:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { createOpenResponses } from '@ai-sdk/open-responses';
|
|
70
|
+
|
|
71
|
+
const lmstudio = createOpenResponses({
|
|
72
|
+
name: 'lmstudio',
|
|
73
|
+
url: 'http://localhost:1234/v1/responses',
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
For the OpenAI Responses API:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { createOpenResponses } from '@ai-sdk/open-responses';
|
|
81
|
+
|
|
82
|
+
const openAIResponses = createOpenResponses({
|
|
83
|
+
name: 'openai',
|
|
84
|
+
url: 'https://api.openai.com/v1/responses',
|
|
85
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
You can use the same setup with another compatible service by changing the
|
|
90
|
+
`name`, `url`, authentication, and model ID.
|
|
91
|
+
|
|
67
92
|
## Language Models
|
|
68
93
|
|
|
69
94
|
The Open Responses provider instance is a function that you can invoke to create a language model:
|
|
70
95
|
|
|
71
96
|
```ts
|
|
72
|
-
const model = openResponses('
|
|
97
|
+
const model = openResponses('your-model-id');
|
|
73
98
|
```
|
|
74
99
|
|
|
100
|
+
The model ID is passed to the endpoint unchanged.
|
|
101
|
+
|
|
75
102
|
You can use Open Responses models with the `generateText` and `streamText` functions,
|
|
76
103
|
and they support structured data generation with [`Output`](/docs/reference/ai-sdk-core/output)
|
|
77
104
|
(see [AI SDK Core](/docs/ai-sdk-core)).
|
|
78
105
|
|
|
79
|
-
###
|
|
106
|
+
### Generate Text
|
|
80
107
|
|
|
81
108
|
```ts
|
|
82
109
|
import { createOpenResponses } from '@ai-sdk/open-responses';
|
|
83
110
|
import { generateText } from 'ai';
|
|
84
111
|
|
|
85
112
|
const openResponses = createOpenResponses({
|
|
86
|
-
name: '
|
|
113
|
+
name: 'lmstudio',
|
|
87
114
|
url: 'http://localhost:1234/v1/responses',
|
|
88
115
|
});
|
|
89
116
|
|
|
90
117
|
const { text } = await generateText({
|
|
91
|
-
model: openResponses('
|
|
118
|
+
model: openResponses('your-model-id'),
|
|
119
|
+
prompt: 'Invent a new holiday and describe its traditions.',
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
console.log(text);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Stream Text
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { createOpenResponses } from '@ai-sdk/open-responses';
|
|
129
|
+
import { streamText } from 'ai';
|
|
130
|
+
|
|
131
|
+
const openResponses = createOpenResponses({
|
|
132
|
+
name: 'lmstudio',
|
|
133
|
+
url: 'http://localhost:1234/v1/responses',
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const result = streamText({
|
|
137
|
+
model: openResponses('your-model-id'),
|
|
92
138
|
prompt: 'Invent a new holiday and describe its traditions.',
|
|
93
139
|
});
|
|
140
|
+
|
|
141
|
+
for await (const textPart of result.textStream) {
|
|
142
|
+
process.stdout.write(textPart);
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Reasoning and Provider Options
|
|
147
|
+
|
|
148
|
+
Use the top-level [`reasoning`](/docs/ai-sdk-core/reasoning) setting to control
|
|
149
|
+
reasoning effort. The provider maps supported values to the Open Responses
|
|
150
|
+
`reasoning.effort` field.
|
|
151
|
+
|
|
152
|
+
The provider also supports `reasoningSummary` through `providerOptions`. The
|
|
153
|
+
provider option key must match the `name` passed to `createOpenResponses`:
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
import {
|
|
157
|
+
createOpenResponses,
|
|
158
|
+
type OpenResponsesLanguageModelOptions,
|
|
159
|
+
} from '@ai-sdk/open-responses';
|
|
160
|
+
import { generateText } from 'ai';
|
|
161
|
+
|
|
162
|
+
const lmstudio = createOpenResponses({
|
|
163
|
+
name: 'lmstudio',
|
|
164
|
+
url: 'http://localhost:1234/v1/responses',
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const { text, reasoningText } = await generateText({
|
|
168
|
+
model: lmstudio('your-reasoning-model-id'),
|
|
169
|
+
reasoning: 'high',
|
|
170
|
+
providerOptions: {
|
|
171
|
+
lmstudio: {
|
|
172
|
+
reasoningSummary: 'detailed',
|
|
173
|
+
} satisfies OpenResponsesLanguageModelOptions,
|
|
174
|
+
},
|
|
175
|
+
prompt: 'Explain why the sky appears blue.',
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
console.log(reasoningText);
|
|
179
|
+
console.log(text);
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
`reasoningSummary` accepts `'auto'`, `'concise'`, or `'detailed'`. Reasoning
|
|
183
|
+
support and accepted values depend on the endpoint and model.
|
|
184
|
+
|
|
185
|
+
## File Inputs
|
|
186
|
+
|
|
187
|
+
The provider supports image and non-image file inputs in user messages. Images
|
|
188
|
+
are sent as `input_image` parts, while other media types, such as PDFs, are
|
|
189
|
+
sent as `input_file` parts.
|
|
190
|
+
|
|
191
|
+
You can provide a file as inline data:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
import { createOpenResponses } from '@ai-sdk/open-responses';
|
|
195
|
+
import { readFileSync } from 'node:fs';
|
|
196
|
+
import { generateText } from 'ai';
|
|
197
|
+
|
|
198
|
+
const openResponses = createOpenResponses({
|
|
199
|
+
name: 'lmstudio',
|
|
200
|
+
url: 'http://localhost:1234/v1/responses',
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const { text } = await generateText({
|
|
204
|
+
model: openResponses('your-file-capable-model-id'),
|
|
205
|
+
messages: [
|
|
206
|
+
{
|
|
207
|
+
role: 'user',
|
|
208
|
+
content: [
|
|
209
|
+
{
|
|
210
|
+
type: 'text',
|
|
211
|
+
text: 'Summarize this document.',
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
type: 'file',
|
|
215
|
+
data: readFileSync('./document.pdf'),
|
|
216
|
+
mediaType: 'application/pdf',
|
|
217
|
+
filename: 'document.pdf',
|
|
218
|
+
},
|
|
219
|
+
],
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
console.log(text);
|
|
94
225
|
```
|
|
95
226
|
|
|
96
|
-
|
|
227
|
+
You can also set `data` to a `URL`. The endpoint and model must support the
|
|
228
|
+
file's media type. Provider file references, such as OpenAI file IDs, and
|
|
229
|
+
file data in `{ type: 'text', text: '...' }` format are not supported by this
|
|
230
|
+
provider.
|
|
231
|
+
|
|
232
|
+
## Limitations
|
|
97
233
|
|
|
98
234
|
- Stop sequences, `topK`, and `seed` are not supported and are ignored with warnings.
|
|
99
|
-
-
|
|
235
|
+
- The provider supports language models only. It does not provide embedding or
|
|
236
|
+
image generation models.
|
|
237
|
+
- AI SDK function tools are supported. Provider-specific built-in tools and
|
|
238
|
+
options require a dedicated provider implementation.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/open-responses",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ai-sdk/provider
|
|
33
|
-
"@ai-sdk/provider": "
|
|
32
|
+
"@ai-sdk/provider": "4.0.3",
|
|
33
|
+
"@ai-sdk/provider-utils": "5.0.9"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "22.19.19",
|