@openrouter/ai-sdk-provider 0.0.3

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 ADDED
@@ -0,0 +1,193 @@
1
+ # OpenRouter Provider for Vercel AI SDK
2
+
3
+ The [OpenRouter](https://openrouter.ai/) provider for the [Vercel AI SDK](https://sdk.vercel.ai/docs)
4
+ contains 160+ language model support for the OpenRouter chat and completion APIs.
5
+
6
+ ## Setup
7
+
8
+ ```bash
9
+ # For pnpm
10
+ pnpm add openrouter-ai-provider
11
+
12
+ # For npm
13
+ npm install openrouter-ai-provider
14
+
15
+ # For yarn
16
+ yarn add openrouter-ai-provider
17
+ ```
18
+
19
+ ## Provider Instance
20
+
21
+ You can import the default provider instance `openrouter` from `openrouter-ai-provider`:
22
+
23
+ ```ts
24
+ import { openrouter } from "openrouter-ai-provider";
25
+ ```
26
+
27
+ ## Example
28
+
29
+ ```ts
30
+ import { openrouter } from "openrouter-ai-provider";
31
+ import { generateText } from "ai";
32
+
33
+ const { text } = await generateText({
34
+ model: openrouter("openai/gpt-4o"),
35
+ prompt: "Write a vegetarian lasagna recipe for 4 people.",
36
+ });
37
+ ```
38
+
39
+ ## Supported models
40
+
41
+ This list is not a definitive list of models supported by OpenRouter, as it constantly changes as we add new models to our system.
42
+ You can find the latest list of models supported by OpenRouter [here](https://openrouter.ai/models).
43
+
44
+ | Model | ID | Input Price ($/1M tokens) | Output Price ($/1M tokens) | Context Window | Moderation |
45
+ | --------------------------------------------- | ------------------------------------------- | ------------------------- | -------------------------- | -------------- | ---------- |
46
+ | Mistral: Mistral Nemo | mistralai/mistral-nemo | $0.3 | $0.3 | 128,000 | None |
47
+ | Mistral: Codestral Mamba | mistralai/codestral-mamba | $0.25 | $0.25 | 256,000 | None |
48
+ | OpenAI: GPT-4o-mini | openai/gpt-4o-mini | $0.15 | $0.6 | 128,000 | Moderated |
49
+ | OpenAI: GPT-4o-mini (2024-07-18) | openai/gpt-4o-mini-2024-07-18 | $0.15 | $0.6 | 128,000 | Moderated |
50
+ | Qwen 2 7B Instruct | qwen/qwen-2-7b-instruct | $0.07 | $0.07 | 32,768 | None |
51
+ | Google: Gemma 2 27B | google/gemma-2-27b-it | $0.27 | $0.27 | 8,192 | None |
52
+ | Nous: Hermes 2 Theta 8B | nousresearch/hermes-2-theta-llama-3-8b | $0.1875 (25% off) | $1.125 (25% off) | 16,384 | None |
53
+ | Magnum 72B | alpindale/magnum-72b | $3.75 (25% off) | $4.5 (25% off) | 16,384 | None |
54
+ | Google: Gemma 2 9B | google/gemma-2-9b-it | $0.08 | $0.08 | 8,192 | None |
55
+ | Google: Gemma 2 9B (free) | google/gemma-2-9b-it:free | $0 (100% off) | $0 (100% off) | 8,192 | None |
56
+ | Llama 3 Stheno 8B v3.3 32K | sao10k/l3-stheno-8b | $0.25 | $1.5 | 32,000 | None |
57
+ | Flavor of The Week | openrouter/flavor-of-the-week | -- | -- | 32,000 | -- |
58
+ | Yi Large | 01-ai/yi-large | $3 | $3 | 32,768 | None |
59
+ | AI21: Jamba Instruct | ai21/jamba-instruct | $0.5 | $0.7 | 256,000 | None |
60
+ | NVIDIA Nemotron-4 340B Instruct | nvidia/nemotron-4-340b-instruct | $4.2 | $4.2 | 4,096 | None |
61
+ | Anthropic: Claude 3.5 Sonnet | anthropic/claude-3.5-sonnet | $3 | $15 | 200,000 | Moderated |
62
+ | Anthropic: Claude 3.5 Sonnet (self-moderated) | anthropic/claude-3.5-sonnet:beta | $3 | $15 | 200,000 | None |
63
+ | Llama 3 Euryale 70B v2.1 | sao10k/l3-euryale-70b | $1.48 | $1.48 | 8,192 | None |
64
+ | Qwen 2 7B Instruct (free) | qwen/qwen-2-7b-instruct:free | $0 (100% off) | $0 (100% off) | 32,768 | None |
65
+ | Phi-3 Medium 4K Instruct | microsoft/phi-3-medium-4k-instruct | $0.14 | $0.14 | 4,000 | None |
66
+ | Dolphin 2.9.2 Mixtral 8x22B 🐬 | cognitivecomputations/dolphin-mixtral-8x22b | $0.9 | $0.9 | 65,536 | None |
67
+ | Qwen 2 72B Instruct | qwen/qwen-2-72b-instruct | $0.56 | $0.77 | 32,768 | None |
68
+ | OpenChat 3.6 8B | openchat/openchat-8b | $0.064 | $0.064 | 8,192 | None |
69
+ | Mistral: Mistral 7B Instruct | mistralai/mistral-7b-instruct | $0.06 | $0.06 | 32,768 | None |
70
+ | Mistral: Mistral 7B Instruct v0.3 | mistralai/mistral-7b-instruct-v0.3 | $0.06 | $0.06 | 32,768 | None |
71
+ | NousResearch: Hermes 2 Pro - Llama-3 8B | nousresearch/hermes-2-pro-llama-3-8b | $0.14 | $0.14 | 8,192 | None |
72
+ | Phi-3 Mini 128K Instruct | microsoft/phi-3-mini-128k-instruct | $0.1 | $0.1 | 128,000 | None |
73
+ | Phi-3 Mini 128K Instruct (free) | microsoft/phi-3-mini-128k-instruct:free | $0 (100% off) | $0 (100% off) | 128,000 | None |
74
+ | Phi-3 Medium 128K Instruct | microsoft/phi-3-medium-128k-instruct | $1 | $1 | 128,000 | None |
75
+ | Phi-3 Medium 128K Instruct (free) | microsoft/phi-3-medium-128k-instruct:free | $0 (100% off) | $0 (100% off) | 128,000 | None |
76
+ | Llama 3 Lumimaid 70B | neversleep/llama-3-lumimaid-70b | $3.375 (25% off) | $4.5 (25% off) | 8,192 | None |
77
+ | Google: Gemini Flash 1.5 | google/gemini-flash-1.5 | $0.25 | $0.75 | 2,800,000 | None |
78
+ | Perplexity: Llama3 Sonar 8B | perplexity/llama-3-sonar-small-32k-chat | $0.2 | $0.2 | 32,768 | None |
79
+ | Perplexity: Llama3 Sonar 8B Online | perplexity/llama-3-sonar-small-32k-online | $0.2 | $0.2 | 28,000 | None |
80
+ | Perplexity: Llama3 Sonar 70B | perplexity/llama-3-sonar-large-32k-chat | $1 | $1 | 32,768 | None |
81
+ | Perplexity: Llama3 Sonar 70B Online | perplexity/llama-3-sonar-large-32k-online | $1 | $1 | 28,000 | None |
82
+ | DeepSeek-V2 Chat | deepseek/deepseek-chat | $0.14 | $0.28 | 128,000 | None |
83
+ | DeepSeek-Coder-V2 | deepseek/deepseek-coder | $0.14 | $0.28 | 128,000 | None |
84
+ | OpenAI: GPT-4o | openai/gpt-4o | $5 | $15 | 128,000 | Moderated |
85
+ | OpenAI: GPT-4o (2024-05-13) | openai/gpt-4o-2024-05-13 | $5 | $15 | 128,000 | Moderated |
86
+ | Meta: Llama 3 8B (Base) | meta-llama/llama-3-8b | $0.18 (10% off) | $0.18 (10% off) | 8,192 | None |
87
+ | Meta: Llama 3 70B (Base) | meta-llama/llama-3-70b | $0.81 (10% off) | $0.81 (10% off) | 8,192 | None |
88
+ | Meta: LlamaGuard 2 8B | meta-llama/llama-guard-2-8b | $0.15 | $0.15 | 8,192 | None |
89
+ | OLMo 7B Instruct | allenai/olmo-7b-instruct | $0.18 (10% off) | $0.18 (10% off) | 2,048 | None |
90
+ | Qwen 1.5 110B Chat | qwen/qwen-110b-chat | $1.62 (10% off) | $1.62 (10% off) | 32,768 | None |
91
+ | Qwen 1.5 72B Chat | qwen/qwen-72b-chat | $0.81 (10% off) | $0.81 (10% off) | 32,768 | None |
92
+ | Qwen 1.5 32B Chat | qwen/qwen-32b-chat | $0.72 (10% off) | $0.72 (10% off) | 32,768 | None |
93
+ | Qwen 1.5 14B Chat | qwen/qwen-14b-chat | $0.27 (10% off) | $0.27 (10% off) | 32,768 | None |
94
+ | Qwen 1.5 7B Chat | qwen/qwen-7b-chat | $0.18 (10% off) | $0.18 (10% off) | 32,768 | None |
95
+ | Qwen 1.5 4B Chat | qwen/qwen-4b-chat | $0.09 (10% off) | $0.09 (10% off) | 32,768 | None |
96
+ | Meta: Llama 3 8B Instruct (free) | meta-llama/llama-3-8b-instruct:free | $0 (100% off) | $0 (100% off) | 8,192 | None |
97
+ | Llama 3 Lumimaid 8B | neversleep/llama-3-lumimaid-8b | $0.1875 | $1.125 | 24,576 | None |
98
+ | Llama 3 Lumimaid 8B (extended) | neversleep/llama-3-lumimaid-8b:extended | $0.1875 (25% off) | $1.125 (25% off) | 24,576 | None |
99
+ | Snowflake: Arctic Instruct | snowflake/snowflake-arctic-instruct | $2.16 (10% off) | $2.16 (10% off) | 4,096 | None |
100
+ | FireLLaVA 13B | fireworks/firellava-13b | $0.2 | $0.2 | 4,096 | None |
101
+ | Lynn: Llama 3 Soliloquy 8B v2 | lynn/soliloquy-l3 | $0.05 | $0.05 | 24,576 | None |
102
+ | Fimbulvetr 11B v2 | sao10k/fimbulvetr-11b-v2 | $0.375 (25% off) | $1.5 (25% off) | 8,192 | None |
103
+ | Meta: Llama 3 8B Instruct (extended) | meta-llama/llama-3-8b-instruct:extended | $0.1875 (25% off) | $1.125 (25% off) | 16,384 | None |
104
+ | Meta: Llama 3 8B Instruct (nitro) | meta-llama/llama-3-8b-instruct:nitro | $0.18 (10% off) | $0.18 (10% off) | 8,192 | None |
105
+ | Meta: Llama 3 70B Instruct (nitro) | meta-llama/llama-3-70b-instruct:nitro | $0.9 | $0.9 | 8,192 | None |
106
+ | Meta: Llama 3 8B Instruct | meta-llama/llama-3-8b-instruct | $0.06 | $0.06 | 8,192 | None |
107
+ | Meta: Llama 3 70B Instruct | meta-llama/llama-3-70b-instruct | $0.52 | $0.75 | 8,192 | None |
108
+ | Mistral: Mixtral 8x22B Instruct | mistralai/mixtral-8x22b-instruct | $0.65 | $0.65 | 65,536 | None |
109
+ | WizardLM-2 8x22B | microsoft/wizardlm-2-8x22b | $0.63 | $0.63 | 65,536 | None |
110
+ | WizardLM-2 7B | microsoft/wizardlm-2-7b | $0.07 | $0.07 | 32,000 | None |
111
+ | Toppy M 7B (nitro) | undi95/toppy-m-7b:nitro | $0.07 | $0.07 | 4,096 | None |
112
+ | Mistral: Mixtral 8x22B (base) | mistralai/mixtral-8x22b | $1.08 (10% off) | $1.08 (10% off) | 65,536 | None |
113
+ | OpenAI: GPT-4 Turbo | openai/gpt-4-turbo | $10 | $30 | 128,000 | Moderated |
114
+ | Google: Gemini Pro 1.5 | google/gemini-pro-1.5 | $2.5 | $7.5 | 2,800,000 | None |
115
+ | Cohere: Command R+ | cohere/command-r-plus | $3 | $15 | 128,000 | None |
116
+ | Databricks: DBRX 132B Instruct | databricks/dbrx-instruct | $1.08 (10% off) | $1.08 (10% off) | 32,768 | None |
117
+ | Midnight Rose 70B | sophosympatheia/midnight-rose-70b | $0.8 | $0.8 | 4,096 | None |
118
+ | Cohere: Command | cohere/command | $1 | $2 | 4,096 | None |
119
+ | Cohere: Command R | cohere/command-r | $0.5 | $1.5 | 128,000 | None |
120
+ | Anthropic: Claude 3 Haiku | anthropic/claude-3-haiku | $0.25 | $1.25 | 200,000 | Moderated |
121
+ | Anthropic: Claude 3 Haiku (self-moderated) | anthropic/claude-3-haiku:beta | $0.25 | $1.25 | 200,000 | None |
122
+ | Google: Gemma 7B (nitro) | google/gemma-7b-it:nitro | $0.07 | $0.07 | 8,192 | None |
123
+ | MythoMax 13B (nitro) | gryphe/mythomax-l2-13b:nitro | $0.2 | $0.2 | 4,096 | None |
124
+ | Anthropic: Claude 3 Opus | anthropic/claude-3-opus | $15 | $75 | 200,000 | Moderated |
125
+ | Anthropic: Claude 3 Sonnet | anthropic/claude-3-sonnet | $3 | $15 | 200,000 | Moderated |
126
+ | Anthropic: Claude 3 Opus (self-moderated) | anthropic/claude-3-opus:beta | $15 | $75 | 200,000 | None |
127
+ | Anthropic: Claude 3 Sonnet (self-moderated) | anthropic/claude-3-sonnet:beta | $3 | $15 | 200,000 | None |
128
+ | Mistral Large | mistralai/mistral-large | $8 | $24 | 32,000 | None |
129
+ | Google: Gemma 7B | google/gemma-7b-it | $0.07 | $0.07 | 8,192 | None |
130
+ | Google: Gemma 7B (free) | google/gemma-7b-it:free | $0 (100% off) | $0 (100% off) | 8,192 | None |
131
+ | Nous: Hermes 2 Mistral 7B DPO | nousresearch/nous-hermes-2-mistral-7b-dpo | $0.18 (10% off) | $0.18 (10% off) | 8,192 | None |
132
+ | Meta: CodeLlama 70B Instruct | meta-llama/codellama-70b-instruct | $0.81 (10% off) | $0.81 (10% off) | 2,048 | None |
133
+ | RWKV v5: Eagle 7B | recursal/eagle-7b | $0 | $0 | 10,000 | None |
134
+ | OpenAI: GPT-3.5 Turbo (older v0613) | openai/gpt-3.5-turbo-0613 | $1 | $2 | 4,095 | Moderated |
135
+ | OpenAI: GPT-4 Turbo Preview | openai/gpt-4-turbo-preview | $10 | $30 | 128,000 | Moderated |
136
+ | ReMM SLERP 13B (extended) | undi95/remm-slerp-l2-13b:extended | $1.125 (25% off) | $1.125 (25% off) | 6,144 | None |
137
+ | Nous: Hermes 2 Mixtral 8x7B DPO | nousresearch/nous-hermes-2-mixtral-8x7b-dpo | $0.45 | $0.45 | 32,768 | None |
138
+ | Nous: Hermes 2 Mixtral 8x7B SFT | nousresearch/nous-hermes-2-mixtral-8x7b-sft | $0.54 (10% off) | $0.54 (10% off) | 32,768 | None |
139
+ | Mistral Tiny | mistralai/mistral-tiny | $0.25 | $0.25 | 32,000 | None |
140
+ | Mistral Small | mistralai/mistral-small | $2 | $6 | 32,000 | None |
141
+ | Mistral Medium | mistralai/mistral-medium | $2.7 | $8.1 | 32,000 | None |
142
+ | Chronos Hermes 13B v2 | austism/chronos-hermes-13b | $0.13 | $0.13 | 4,096 | None |
143
+ | Noromaid Mixtral 8x7B Instruct | neversleep/noromaid-mixtral-8x7b-instruct | $8 | $8 | 8,000 | None |
144
+ | Nous: Hermes 2 Yi 34B | nousresearch/nous-hermes-yi-34b | $0.72 (10% off) | $0.72 (10% off) | 4,096 | None |
145
+ | Mistral: Mistral 7B Instruct v0.2 | mistralai/mistral-7b-instruct-v0.2 | $0.06 | $0.06 | 32,768 | None |
146
+ | Dolphin 2.6 Mixtral 8x7B 🐬 | cognitivecomputations/dolphin-mixtral-8x7b | $0.5 | $0.5 | 32,768 | None |
147
+ | Google: Gemini Pro 1.0 | google/gemini-pro | $0.125 | $0.375 | 91,728 | None |
148
+ | Google: Gemini Pro Vision 1.0 | google/gemini-pro-vision | $0.125 | $0.375 | 45,875 | None |
149
+ | Mixtral 8x7B (base) | mistralai/mixtral-8x7b | $0.54 (10% off) | $0.54 (10% off) | 32,768 | None |
150
+ | Mixtral 8x7B Instruct | mistralai/mixtral-8x7b-instruct | $0.24 | $0.24 | 32,768 | None |
151
+ | RWKV v5 World 3B | rwkv/rwkv-5-world-3b | $0 | $0 | 10,000 | None |
152
+ | RWKV v5 3B AI Town | recursal/rwkv-5-3b-ai-town | $0 | $0 | 10,000 | None |
153
+ | StripedHyena Nous 7B | togethercomputer/stripedhyena-nous-7b | $0.18 (10% off) | $0.18 (10% off) | 32,768 | None |
154
+ | StripedHyena Hessian 7B (base) | togethercomputer/stripedhyena-hessian-7b | $0.18 (10% off) | $0.18 (10% off) | 32,768 | None |
155
+ | Psyfighter v2 13B | koboldai/psyfighter-13b-2 | $1 (90% off) | $1 (90% off) | 4,096 | None |
156
+ | Yi 34B Chat | 01-ai/yi-34b-chat | $0.72 (10% off) | $0.72 (10% off) | 4,096 | None |
157
+ | Yi 34B (base) | 01-ai/yi-34b | $0.72 (10% off) | $0.72 (10% off) | 4,096 | None |
158
+ | Yi 6B (base) | 01-ai/yi-6b | $0.18 (10% off) | $0.18 (10% off) | 4,096 | None |
159
+ | MythoMist 7B | gryphe/mythomist-7b | $0.375 (25% off) | $0.375 (25% off) | 32,768 | None |
160
+ | Nous: Capybara 7B | nousresearch/nous-capybara-7b | $0.18 (10% off) | $0.18 (10% off) | 8,192 | None |
161
+ | Nous: Capybara 7B (free) | nousresearch/nous-capybara-7b:free | $0 (100% off) | $0 (100% off) | 8,192 | None |
162
+ | OpenChat 3.5 7B | openchat/openchat-7b | $0.07 | $0.07 | 8,192 | None |
163
+ | OpenChat 3.5 7B (free) | openchat/openchat-7b:free | $0 (100% off) | $0 (100% off) | 8,192 | None |
164
+ | Noromaid 20B | neversleep/noromaid-20b | $1.5 (25% off) | $2.25 (25% off) | 8,192 | None |
165
+ | MythoMist 7B (free) | gryphe/mythomist-7b:free | $0 (100% off) | $0 (100% off) | 32,768 | None |
166
+ | Neural Chat 7B v3.1 | intel/neural-chat-7b | $5 (50% off) | $5 (50% off) | 4,096 | None |
167
+ | Anthropic: Claude v2 | anthropic/claude-2 | $8 | $24 | 200,000 | Moderated |
168
+ | Anthropic: Claude v2.1 | anthropic/claude-2.1 | $8 | $24 | 200,000 | Moderated |
169
+ | Anthropic: Claude Instant v1.1 | anthropic/claude-instant-1.1 | $0.8 | $2.4 | 100,000 | Moderated |
170
+ | Anthropic: Claude v2 (self-moderated) | anthropic/claude-2:beta | $8 | $24 | 200,000 | None |
171
+ | Anthropic: Claude v2.1 (self-moderated) | anthropic/claude-2.1:beta | $8 | $24 | 200,000 | None |
172
+ | OpenHermes 2.5 Mistral 7B | teknium/openhermes-2.5-mistral-7b | $0.17 | $0.17 | 4,096 | None |
173
+ | OpenAI: GPT-4 Vision | openai/gpt-4-vision-preview | $10 | $30 | 128,000 | Moderated |
174
+ | lzlv 70B | lizpreciatior/lzlv-70b-fp16-hf | $0.58 | $0.78 | 4,096 | None |
175
+ | Toppy M 7B | undi95/toppy-m-7b | $0.07 | $0.07 | 4,096 | None |
176
+ | Goliath 120B | alpindale/goliath-120b | $9.375 (25% off) | $9.375 (25% off) | 6,144 | None |
177
+ | Toppy M 7B (free) | undi95/toppy-m-7b:free | $0 (100% off) | $0 (100% off) | 4,096 | None |
178
+ | Auto (best for prompt) | openrouter/auto | -- | -- | 200,000 | -- |
179
+ | OpenAI: GPT-3.5 Turbo 16k (older v1106) | openai/gpt-3.5-turbo-1106 | $1 | $2 | 16,385 | Moderated |
180
+ | OpenAI: GPT-4 Turbo (older v1106) | openai/gpt-4-1106-preview | $10 | $30 | 128,000 | Moderated |
181
+ | Hugging Face: Zephyr 7B (free) | huggingfaceh4/zephyr-7b-beta:free | $0 (100% off) | $0 (100% off) | 4,096 | None |
182
+ | Google: PaLM 2 Chat 32k | google/palm-2-chat-bison-32k | $0.25 | $0.5 | 91,750 | None |
183
+ | Google: PaLM 2 Code Chat 32k | google/palm-2-codechat-bison-32k | $0.25 | $0.5 | 91,750 | None |
184
+ | OpenHermes 2 Mistral 7B | teknium/openhermes-2-mistral-7b | $0.18 (10% off) | $0.18 (10% off) | 8,192 | None |
185
+ | Mistral OpenOrca 7B | open-orca/mistral-7b-openorca | $0.18 (10% off) | $0.18 (10% off) | 8,192 | None |
186
+ | Airoboros 70B | jondurbin/airoboros-l2-70b | $0.5 | $0.5 | 4,096 | None |
187
+ | MythoMax 13B (extended) | gryphe/mythomax-l2-13b:extended | $1.125 (25% off) | $1.125 (25% off) | 8,192 | None |
188
+ | Xwin 70B | xwin-lm/xwin-lm-70b | $3.75 (25% off) | $3.75 (25% off) | 8,192 | None |
189
+ | OpenAI: GPT-3.5 Turbo Instruct | openai/gpt-3.5-turbo-instruct | $1.5 | $2 | 4,095 | Moderated |
190
+ | Mistral: Mistral 7B Instruct v0.1 | mistralai/mistral-7b-instruct-v0.1 | $0.06 | $0.06 | 4,096 | None |
191
+ | Mistral: Mistral 7B Instruct (free) | mistralai/mistral-7b-instruct:free | $0 (100% off) | $0 (100% off) | 32,768 | None |
192
+ | Pygmalion: Mythalion 13B | pygmalionai/mythalion-13b | $1.125 (25% off) | $1.125 (25% off) | 8,192 | None |
193
+ | OpenAI: GPT-3.5 Turbo 16k | openai/gpt-3.5-turbo-16k | $3 | $4 | 16,385 | Moderated |
@@ -0,0 +1,228 @@
1
+ import { LanguageModelV1 } from '@ai-sdk/provider';
2
+
3
+ type OpenRouterChatModelId = string;
4
+ interface OpenRouterChatSettings {
5
+ /**
6
+ Modify the likelihood of specified tokens appearing in the completion.
7
+
8
+ Accepts a JSON object that maps tokens (specified by their token ID in
9
+ the GPT tokenizer) to an associated bias value from -100 to 100. You
10
+ can use this tokenizer tool to convert text to token IDs. Mathematically,
11
+ the bias is added to the logits generated by the model prior to sampling.
12
+ The exact effect will vary per model, but values between -1 and 1 should
13
+ decrease or increase likelihood of selection; values like -100 or 100
14
+ should result in a ban or exclusive selection of the relevant token.
15
+
16
+ As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
17
+ token from being generated.
18
+ */
19
+ logitBias?: Record<number, number>;
20
+ /**
21
+ Return the log probabilities of the tokens. Including logprobs will increase
22
+ the response size and can slow down response times. However, it can
23
+ be useful to better understand how the model is behaving.
24
+
25
+ Setting to true will return the log probabilities of the tokens that
26
+ were generated.
27
+
28
+ Setting to a number will return the log probabilities of the top n
29
+ tokens that were generated.
30
+ */
31
+ logprobs?: boolean | number;
32
+ /**
33
+ Whether to enable parallel function calling during tool use. Default to true.
34
+ */
35
+ parallelToolCalls?: boolean;
36
+ /**
37
+ A unique identifier representing your end-user, which can help OpenRouter to
38
+ monitor and detect abuse. Learn more.
39
+ */
40
+ user?: string;
41
+ }
42
+
43
+ type OpenRouterChatConfig = {
44
+ provider: string;
45
+ compatibility: "strict" | "compatible";
46
+ headers: () => Record<string, string | undefined>;
47
+ url: (options: {
48
+ modelId: string;
49
+ path: string;
50
+ }) => string;
51
+ fetch?: typeof fetch;
52
+ };
53
+ declare class OpenRouterChatLanguageModel implements LanguageModelV1 {
54
+ readonly specificationVersion = "v1";
55
+ readonly defaultObjectGenerationMode = "tool";
56
+ readonly modelId: OpenRouterChatModelId;
57
+ readonly settings: OpenRouterChatSettings;
58
+ private readonly config;
59
+ constructor(modelId: OpenRouterChatModelId, settings: OpenRouterChatSettings, config: OpenRouterChatConfig);
60
+ get provider(): string;
61
+ private getArgs;
62
+ doGenerate(options: Parameters<LanguageModelV1["doGenerate"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doGenerate"]>>>;
63
+ doStream(options: Parameters<LanguageModelV1["doStream"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doStream"]>>>;
64
+ }
65
+
66
+ type OpenRouterCompletionModelId = "openai/gpt-3.5-turbo-instruct" | (string & {});
67
+ interface OpenRouterCompletionSettings {
68
+ /**
69
+ Echo back the prompt in addition to the completion.
70
+ */
71
+ echo?: boolean;
72
+ /**
73
+ Modify the likelihood of specified tokens appearing in the completion.
74
+
75
+ Accepts a JSON object that maps tokens (specified by their token ID in
76
+ the GPT tokenizer) to an associated bias value from -100 to 100. You
77
+ can use this tokenizer tool to convert text to token IDs. Mathematically,
78
+ the bias is added to the logits generated by the model prior to sampling.
79
+ The exact effect will vary per model, but values between -1 and 1 should
80
+ decrease or increase likelihood of selection; values like -100 or 100
81
+ should result in a ban or exclusive selection of the relevant token.
82
+
83
+ As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
84
+ token from being generated.
85
+ */
86
+ logitBias?: Record<number, number>;
87
+ /**
88
+ Return the log probabilities of the tokens. Including logprobs will increase
89
+ the response size and can slow down response times. However, it can
90
+ be useful to better understand how the model is behaving.
91
+
92
+ Setting to true will return the log probabilities of the tokens that
93
+ were generated.
94
+
95
+ Setting to a number will return the log probabilities of the top n
96
+ tokens that were generated.
97
+ */
98
+ logprobs?: boolean | number;
99
+ /**
100
+ The suffix that comes after a completion of inserted text.
101
+ */
102
+ suffix?: string;
103
+ /**
104
+ A unique identifier representing your end-user, which can help OpenRouter to
105
+ monitor and detect abuse. Learn more.
106
+ */
107
+ user?: string;
108
+ }
109
+
110
+ type OpenRouterCompletionConfig = {
111
+ provider: string;
112
+ compatibility: "strict" | "compatible";
113
+ headers: () => Record<string, string | undefined>;
114
+ url: (options: {
115
+ modelId: string;
116
+ path: string;
117
+ }) => string;
118
+ fetch?: typeof fetch;
119
+ };
120
+ declare class OpenRouterCompletionLanguageModel implements LanguageModelV1 {
121
+ readonly specificationVersion = "v1";
122
+ readonly defaultObjectGenerationMode: undefined;
123
+ readonly modelId: OpenRouterCompletionModelId;
124
+ readonly settings: OpenRouterCompletionSettings;
125
+ private readonly config;
126
+ constructor(modelId: OpenRouterCompletionModelId, settings: OpenRouterCompletionSettings, config: OpenRouterCompletionConfig);
127
+ get provider(): string;
128
+ private getArgs;
129
+ doGenerate(options: Parameters<LanguageModelV1["doGenerate"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doGenerate"]>>>;
130
+ doStream(options: Parameters<LanguageModelV1["doStream"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doStream"]>>>;
131
+ }
132
+
133
+ interface OpenRouterProvider {
134
+ (modelId: "openai/gpt-3.5-turbo-instruct", settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
135
+ (modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
136
+ languageModel(modelId: "openai/gpt-3.5-turbo-instruct", settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
137
+ languageModel(modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
138
+ /**
139
+ Creates an OpenRouter chat model for text generation.
140
+ */
141
+ chat(modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
142
+ /**
143
+ Creates an OpenRouter completion model for text generation.
144
+ */
145
+ completion(modelId: OpenRouterCompletionModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
146
+ }
147
+ interface OpenRouterProviderSettings {
148
+ /**
149
+ Base URL for the OpenRouter API calls.
150
+ */
151
+ baseURL?: string;
152
+ /**
153
+ @deprecated Use `baseURL` instead.
154
+ */
155
+ baseUrl?: string;
156
+ /**
157
+ API key for authenticating requests.
158
+ */
159
+ apiKey?: string;
160
+ /**
161
+ OpenRouter Organization.
162
+ */
163
+ organization?: string;
164
+ /**
165
+ OpenRouter project.
166
+ */
167
+ project?: string;
168
+ /**
169
+ Custom headers to include in the requests.
170
+ */
171
+ headers?: Record<string, string>;
172
+ /**
173
+ OpenRouter compatibility mode. Should be set to `strict` when using the OpenRouter API,
174
+ and `compatible` when using 3rd party providers. In `compatible` mode, newer
175
+ information such as streamOptions are not being sent. Defaults to 'compatible'.
176
+ */
177
+ compatibility?: "strict" | "compatible";
178
+ /**
179
+ Custom fetch implementation. You can use it as a middleware to intercept requests,
180
+ or to provide a custom fetch implementation for e.g. testing.
181
+ */
182
+ fetch?: typeof fetch;
183
+ }
184
+ /**
185
+ Create an OpenRouter provider instance.
186
+ */
187
+ declare function createOpenRouter(options?: OpenRouterProviderSettings): OpenRouterProvider;
188
+ /**
189
+ Default OpenRouter provider instance. It uses 'strict' compatibility mode.
190
+ */
191
+ declare const openrouter: OpenRouterProvider;
192
+
193
+ /**
194
+ @deprecated Use `createOpenRouter` instead.
195
+ */
196
+ declare class OpenRouter {
197
+ /**
198
+ Use a different URL prefix for API calls, e.g. to use proxy servers.
199
+ The default prefix is `https://openrouter.ai/api/v1`.
200
+ */
201
+ readonly baseURL: string;
202
+ /**
203
+ API key that is being send using the `Authorization` header.
204
+ It defaults to the `OPENAI_API_KEY` environment variable.
205
+ */
206
+ readonly apiKey?: string;
207
+ /**
208
+ OpenRouter Organization.
209
+ */
210
+ readonly organization?: string;
211
+ /**
212
+ OpenRouter project.
213
+ */
214
+ readonly project?: string;
215
+ /**
216
+ Custom headers to include in the requests.
217
+ */
218
+ readonly headers?: Record<string, string>;
219
+ /**
220
+ * Creates a new OpenRouter provider instance.
221
+ */
222
+ constructor(options?: OpenRouterProviderSettings);
223
+ private get baseConfig();
224
+ chat(modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
225
+ completion(modelId: OpenRouterCompletionModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
226
+ }
227
+
228
+ export { OpenRouter, type OpenRouterProvider, type OpenRouterProviderSettings, createOpenRouter, openrouter };