@alpic80/rivet-ai-sdk-provider 2.0.0 → 2.0.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/README.md +12 -170
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,199 +1,41 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Rivet Provider for Vercel AI SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This is the [Rivet](https://rivet.ironcladapp.com) provider for the [Vercel AI SDK](https://sdk.vercel.ai/docs) giving you access to run your Rivet Graphs as a supported LM.
|
|
4
4
|
|
|
5
5
|
## Setup for AI SDK v5
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
# For pnpm
|
|
9
|
-
pnpm add @
|
|
9
|
+
pnpm add @alpic80/rivet-ai-sdk-provider
|
|
10
10
|
|
|
11
11
|
# For npm
|
|
12
|
-
npm install @
|
|
12
|
+
npm install @alpic80/rivet-ai-sdk-provider
|
|
13
13
|
|
|
14
14
|
# For yarn
|
|
15
|
-
yarn add @
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## (LEGACY) Setup for AI SDK v4
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
# For pnpm
|
|
22
|
-
pnpm add @openrouter/ai-sdk-provider@ai-sdk-v4
|
|
23
|
-
|
|
24
|
-
# For npm
|
|
25
|
-
npm install @openrouter/ai-sdk-provider@ai-sdk-v4
|
|
26
|
-
|
|
27
|
-
# For yarn
|
|
28
|
-
yarn add @openrouter/ai-sdk-provider@ai-sdk-v4
|
|
29
|
-
|
|
15
|
+
yarn add @alpic80/rivet-ai-sdk-provider
|
|
30
16
|
```
|
|
31
17
|
|
|
32
18
|
## Provider Instance
|
|
33
19
|
|
|
34
|
-
You can import the default provider instance `
|
|
20
|
+
You can import the default provider instance `rivet` from `@alpic80/rivet-ai-sdk-provider`:
|
|
35
21
|
|
|
36
22
|
```ts
|
|
37
|
-
import {
|
|
23
|
+
import { rivet } from '@alpic80/rivet-ai-sdk-provider';
|
|
38
24
|
```
|
|
39
25
|
|
|
40
26
|
## Example
|
|
41
27
|
|
|
42
28
|
```ts
|
|
43
|
-
import {
|
|
29
|
+
import { rivet } from '"@alpic80/rivet-ai-sdk-provider';
|
|
44
30
|
import { generateText } from 'ai';
|
|
45
31
|
|
|
46
32
|
const { text } = await generateText({
|
|
47
|
-
model:
|
|
33
|
+
model: rivet('myGraph.rivet-project'),
|
|
48
34
|
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
49
35
|
});
|
|
50
36
|
```
|
|
51
37
|
|
|
52
|
-
##
|
|
53
|
-
|
|
54
|
-
This list is not a definitive list of models supported by OpenRouter, as it constantly changes as we add new models (and deprecate old ones) to our system. You can find the latest list of models supported by OpenRouter [here](https://openrouter.ai/models).
|
|
55
|
-
|
|
56
|
-
You can find the latest list of tool-supported models supported by OpenRouter [here](https://openrouter.ai/models?order=newest&supported_parameters=tools). (Note: This list may contain models that are not compatible with the AI SDK.)
|
|
57
|
-
|
|
58
|
-
## Passing Extra Body to OpenRouter
|
|
59
|
-
|
|
60
|
-
There are 3 ways to pass extra body to OpenRouter:
|
|
61
|
-
|
|
62
|
-
1. Via the `providerOptions.openrouter` property:
|
|
63
|
-
|
|
64
|
-
```typescript
|
|
65
|
-
import { createOpenRouter } from '@openrouter/ai-sdk-provider';
|
|
66
|
-
import { streamText } from 'ai';
|
|
67
|
-
|
|
68
|
-
const openrouter = createOpenRouter({ apiKey: 'your-api-key' });
|
|
69
|
-
const model = openrouter('anthropic/claude-3.7-sonnet:thinking');
|
|
70
|
-
await streamText({
|
|
71
|
-
model,
|
|
72
|
-
messages: [{ role: 'user', content: 'Hello' }],
|
|
73
|
-
providerOptions: {
|
|
74
|
-
openrouter: {
|
|
75
|
-
reasoning: {
|
|
76
|
-
max_tokens: 10,
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
2. Via the `extraBody` property in the model settings:
|
|
84
|
-
|
|
85
|
-
```typescript
|
|
86
|
-
import { createOpenRouter } from '@openrouter/ai-sdk-provider';
|
|
87
|
-
import { streamText } from 'ai';
|
|
88
|
-
|
|
89
|
-
const openrouter = createOpenRouter({ apiKey: 'your-api-key' });
|
|
90
|
-
const model = openrouter('anthropic/claude-3.7-sonnet:thinking', {
|
|
91
|
-
extraBody: {
|
|
92
|
-
reasoning: {
|
|
93
|
-
max_tokens: 10,
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
await streamText({
|
|
98
|
-
model,
|
|
99
|
-
messages: [{ role: 'user', content: 'Hello' }],
|
|
100
|
-
});
|
|
101
|
-
```
|
|
38
|
+
## Required Configuration
|
|
102
39
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
```typescript
|
|
106
|
-
import { createOpenRouter } from '@openrouter/ai-sdk-provider';
|
|
107
|
-
import { streamText } from 'ai';
|
|
108
|
-
|
|
109
|
-
const openrouter = createOpenRouter({
|
|
110
|
-
apiKey: 'your-api-key',
|
|
111
|
-
extraBody: {
|
|
112
|
-
reasoning: {
|
|
113
|
-
max_tokens: 10,
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
const model = openrouter('anthropic/claude-3.7-sonnet:thinking');
|
|
118
|
-
await streamText({
|
|
119
|
-
model,
|
|
120
|
-
messages: [{ role: 'user', content: 'Hello' }],
|
|
121
|
-
});
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
## Anthropic Prompt Caching
|
|
125
|
-
|
|
126
|
-
You can include Anthropic-specific options directly in your messages when using functions like `streamText`. The OpenRouter provider will automatically convert these messages to the correct format internally.
|
|
127
|
-
|
|
128
|
-
### Basic Usage
|
|
129
|
-
|
|
130
|
-
```typescript
|
|
131
|
-
import { createOpenRouter } from '@openrouter/ai-sdk-provider';
|
|
132
|
-
import { streamText } from 'ai';
|
|
133
|
-
|
|
134
|
-
const openrouter = createOpenRouter({ apiKey: 'your-api-key' });
|
|
135
|
-
const model = openrouter('anthropic/<supported-caching-model>');
|
|
136
|
-
|
|
137
|
-
await streamText({
|
|
138
|
-
model,
|
|
139
|
-
messages: [
|
|
140
|
-
{
|
|
141
|
-
role: 'system',
|
|
142
|
-
content:
|
|
143
|
-
'You are a podcast summary assistant. You are detail-oriented and critical about the content.',
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
role: 'user',
|
|
147
|
-
content: [
|
|
148
|
-
{
|
|
149
|
-
type: 'text',
|
|
150
|
-
text: 'Given the text body below:',
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
type: 'text',
|
|
154
|
-
text: `<LARGE BODY OF TEXT>`,
|
|
155
|
-
providerOptions: {
|
|
156
|
-
openrouter: {
|
|
157
|
-
cacheControl: { type: 'ephemeral' },
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
type: 'text',
|
|
163
|
-
text: 'List the speakers?',
|
|
164
|
-
},
|
|
165
|
-
],
|
|
166
|
-
},
|
|
167
|
-
],
|
|
168
|
-
});
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
## Use Cases
|
|
172
|
-
|
|
173
|
-
### Usage Accounting
|
|
174
|
-
|
|
175
|
-
The provider supports [OpenRouter usage accounting](https://openrouter.ai/docs/use-cases/usage-accounting), which allows you to track token usage details directly in your API responses, without making additional API calls.
|
|
176
|
-
|
|
177
|
-
```typescript
|
|
178
|
-
// Enable usage accounting
|
|
179
|
-
const model = openrouter('openai/gpt-3.5-turbo', {
|
|
180
|
-
usage: {
|
|
181
|
-
include: true,
|
|
182
|
-
},
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
// Access usage accounting data
|
|
186
|
-
const result = await generateText({
|
|
187
|
-
model,
|
|
188
|
-
prompt: 'Hello, how are you today?',
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
// Provider-specific usage details (available in providerMetadata)
|
|
192
|
-
if (result.providerMetadata?.openrouter?.usage) {
|
|
193
|
-
console.log('Cost:', result.providerMetadata.openrouter.usage.cost);
|
|
194
|
-
console.log(
|
|
195
|
-
'Total Tokens:',
|
|
196
|
-
result.providerMetadata.openrouter.usage.totalTokens,
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
```
|
|
40
|
+
In order to use the Rivet AI SDK provider you will need to also install and run the Adion custom Rivet server
|
|
41
|
+
available on npm (@alpic80/rivet-cli) and to configure it with support for PROJECTS_ROOT_DIR (see serve.md for details)
|
package/dist/index.js
CHANGED
|
@@ -1109,7 +1109,7 @@ prepare tools input:${printObject(tools)}`);
|
|
|
1109
1109
|
}
|
|
1110
1110
|
|
|
1111
1111
|
// src/version.ts
|
|
1112
|
-
var VERSION = true ? "2.0.
|
|
1112
|
+
var VERSION = true ? "2.0.1" : "0.0.0-test";
|
|
1113
1113
|
|
|
1114
1114
|
// src/post-to-api.ts
|
|
1115
1115
|
var getOriginalFetch = () => globalThis.fetch;
|
package/dist/index.mjs
CHANGED
|
@@ -1076,7 +1076,7 @@ prepare tools input:${printObject(tools)}`);
|
|
|
1076
1076
|
}
|
|
1077
1077
|
|
|
1078
1078
|
// src/version.ts
|
|
1079
|
-
var VERSION = true ? "2.0.
|
|
1079
|
+
var VERSION = true ? "2.0.1" : "0.0.0-test";
|
|
1080
1080
|
|
|
1081
1081
|
// src/post-to-api.ts
|
|
1082
1082
|
var getOriginalFetch = () => globalThis.fetch;
|