@@ -44,27 +44,66 @@ You can find the latest list of tool-supported models supported by OpenRouter [h
44
44
45
45
## Passing Extra Body to OpenRouter
46
46
47
- When you want to pass extra body to OpenRouter or to the upstream provider, you can do so by setting the ` extraBody ` property on the language model.
48
-
49
- ``` typescript
50
- import { createOpenRouter } from ' @openrouter/ai-sdk-provider' ;
51
-
52
- const provider = createOpenRouter ({
53
- apiKey: ' your-api-key' ,
54
- // Extra body to pass to OpenRouter
55
- extraBody: {
56
- custom_field: ' custom_value' ,
57
- providers: {
58
- anthropic: {
59
- custom_field: ' custom_value' ,
60
- },
61
- },
62
- },
63
- });
64
- const model = provider .chat (' anthropic/claude-3.5-sonnet' );
65
- const response = await model .doStream ({
66
- inputFormat: ' prompt' ,
67
- mode: { type: ' regular' },
68
- prompt: [{ role: ' user' , content: ' Hello' }],
69
- });
70
- ```
47
+ There are 3 ways to pass extra body to OpenRouter:
48
+
49
+ 1 . Via the ` providerOptions.openrouter ` property:
50
+
51
+ ``` typescript
52
+ import { createOpenRouter } from ' @openrouter/ai-sdk-provider' ;
53
+ import { streamText } from ' ai' ;
54
+
55
+ const openrouter = createOpenRouter ({ apiKey: ' your-api-key' });
56
+ const model = openrouter (' anthropic/claude-3.7-sonnet:thinking' );
57
+ await streamText ({
58
+ model ,
59
+ messages: [{ role: ' user' , content: ' Hello' }],
60
+ providerOptions: {
61
+ openrouter: {
62
+ reasoning: {
63
+ max_tokens: 10 ,
64
+ },
65
+ },
66
+ },
67
+ });
68
+ ```
69
+
70
+ 2 . Via the ` extraBody ` property in the model settings:
71
+
72
+ ``` typescript
73
+ import { createOpenRouter } from ' @openrouter/ai-sdk-provider' ;
74
+ import { streamText } from ' ai' ;
75
+
76
+ const openrouter = createOpenRouter ({ apiKey: ' your-api-key' });
77
+ const model = openrouter (' anthropic/claude-3.7-sonnet:thinking' , {
78
+ extraBody: {
79
+ reasoning: {
80
+ max_tokens: 10 ,
81
+ },
82
+ },
83
+ });
84
+ await streamText ({
85
+ model ,
86
+ messages: [{ role: ' user' , content: ' Hello' }],
87
+ });
88
+ ```
89
+
90
+ 3 . Via the ` extraBody ` property in the model factory.
91
+
92
+ ``` typescript
93
+ import { createOpenRouter } from ' @openrouter/ai-sdk-provider' ;
94
+ import { streamText } from ' ai' ;
95
+
96
+ const openrouter = createOpenRouter ({
97
+ apiKey: ' your-api-key' ,
98
+ extraBody: {
99
+ reasoning: {
100
+ max_tokens: 10 ,
101
+ },
102
+ },
103
+ });
104
+ const model = openrouter (' anthropic/claude-3.7-sonnet:thinking' );
105
+ await streamText ({
106
+ model ,
107
+ messages: [{ role: ' user' , content: ' Hello' }],
108
+ });
109
+ ```
0 commit comments