@elizaos/plugin-openrouter 2.0.0-alpha.9 → 2.0.0-beta.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/LICENSE +21 -0
- package/README.md +125 -0
- package/auto-enable.ts +17 -0
- package/dist/browser/index.browser.js +684 -2
- package/dist/browser/index.browser.js.map +12 -4
- package/dist/cjs/index.node.cjs +677 -6
- package/dist/cjs/index.node.cjs.map +12 -4
- package/dist/node/index.node.js +684 -2
- package/dist/node/index.node.js.map +12 -4
- package/package.json +29 -13
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Shaw Walters and elizaOS Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# @elizaos/plugin-openrouter
|
|
2
|
+
|
|
3
|
+
This plugin provides integration with various models available through the OpenRouter API via the ElizaOS platform.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Add the plugin to your character configuration:
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
"plugins": ["@elizaos/plugin-openrouter"]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Configuration
|
|
14
|
+
|
|
15
|
+
The plugin requires the OpenRouter API key and can be configured via environment variables or character settings.
|
|
16
|
+
|
|
17
|
+
**Character Settings Example:**
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
"settings": {
|
|
21
|
+
"OPENROUTER_API_KEY": "your_openrouter_api_key",
|
|
22
|
+
"OPENROUTER_BASE_URL": "https://openrouter.ai/api/v1", // Optional: Default is OpenRouter endpoint
|
|
23
|
+
"OPENROUTER_SMALL_MODEL": "google/gemini-flash", // Optional: Overrides default small model
|
|
24
|
+
"OPENROUTER_LARGE_MODEL": "google/gemini-pro", // Optional: Overrides default large model
|
|
25
|
+
"OPENROUTER_IMAGE_MODEL": "x-ai/grok-2-vision-1212", // Optional: Overrides default image model
|
|
26
|
+
"OPENROUTER_IMAGE_GENERATION_MODEL": "google/gemini-2.5-flash-image-preview", // Optional: Overrides default image generation model
|
|
27
|
+
"OPENROUTER_EMBEDDING_MODEL": "openai/text-embedding-3-small", // Optional: Overrides default embedding model
|
|
28
|
+
"OPENROUTER_EMBEDDING_DIMENSIONS": "1536", // Optional: Sets embedding vector dimensions (256, 384, 512, 768, 1024, 1536, 2048, 3072)
|
|
29
|
+
"OPENROUTER_BROWSER_BASE_URL": "https://your-proxy.example.com/openrouter"
|
|
30
|
+
// Fallbacks if specific OPENROUTER models are not set
|
|
31
|
+
"SMALL_MODEL": "google/gemini-flash",
|
|
32
|
+
"LARGE_MODEL": "google/gemini-pro",
|
|
33
|
+
"IMAGE_MODEL": "x-ai/grok-2-vision-1212",
|
|
34
|
+
"IMAGE_GENERATION_MODEL": "google/gemini-2.5-flash-image-preview",
|
|
35
|
+
"EMBEDDING_MODEL": "openai/text-embedding-3-small",
|
|
36
|
+
"EMBEDDING_DIMENSIONS": "1536"
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**`.env` File Example:**
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
OPENROUTER_API_KEY=your_openrouter_api_key
|
|
44
|
+
# Optional overrides:
|
|
45
|
+
OPENROUTER_BASE_URL=https://openrouter.ai/api/v1
|
|
46
|
+
OPENROUTER_SMALL_MODEL=google/gemini-flash
|
|
47
|
+
OPENROUTER_LARGE_MODEL=google/gemini-pro
|
|
48
|
+
OPENROUTER_IMAGE_MODEL=x-ai/grok-2-vision-1212
|
|
49
|
+
OPENROUTER_IMAGE_GENERATION_MODEL=google/gemini-2.5-flash-image-preview
|
|
50
|
+
OPENROUTER_EMBEDDING_MODEL=openai/text-embedding-3-small
|
|
51
|
+
OPENROUTER_EMBEDDING_DIMENSIONS=1536
|
|
52
|
+
# Browser proxy (frontend builds only)
|
|
53
|
+
OPENROUTER_BROWSER_BASE_URL=https://your-proxy.example.com/openrouter
|
|
54
|
+
# Fallbacks if specific OPENROUTER models are not set
|
|
55
|
+
SMALL_MODEL=google/gemini-flash
|
|
56
|
+
LARGE_MODEL=google/gemini-pro
|
|
57
|
+
IMAGE_MODEL=x-ai/grok-2-vision-1212
|
|
58
|
+
IMAGE_GENERATION_MODEL=google/gemini-2.5-flash-image-preview
|
|
59
|
+
EMBEDDING_MODEL=openai/text-embedding-3-small
|
|
60
|
+
EMBEDDING_DIMENSIONS=1536
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Configuration Options
|
|
64
|
+
|
|
65
|
+
- `OPENROUTER_API_KEY` (required): Your OpenRouter API key.
|
|
66
|
+
- `OPENROUTER_BASE_URL`: Custom API endpoint (default: https://openrouter.ai/api/v1).
|
|
67
|
+
- `OPENROUTER_BROWSER_BASE_URL`: Browser-only base URL to a proxy endpoint that forwards requests to OpenRouter without exposing keys.
|
|
68
|
+
|
|
69
|
+
### Browser mode and proxying
|
|
70
|
+
|
|
71
|
+
When bundled for the browser, this plugin avoids sending Authorization headers. Set `OPENROUTER_BROWSER_BASE_URL` to a server-side proxy you control that injects the OpenRouter API key. This prevents exposing secrets in frontend builds.
|
|
72
|
+
|
|
73
|
+
Example minimal proxy (Express):
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import express from "express";
|
|
77
|
+
import fetch from "node-fetch";
|
|
78
|
+
|
|
79
|
+
const app = express();
|
|
80
|
+
app.use(express.json());
|
|
81
|
+
|
|
82
|
+
app.post("/openrouter/*", async (req, res) => {
|
|
83
|
+
const url = `https://openrouter.ai/api/v1/${req.params[0]}`;
|
|
84
|
+
const r = await fetch(url, {
|
|
85
|
+
method: "POST",
|
|
86
|
+
headers: {
|
|
87
|
+
Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}`,
|
|
88
|
+
"Content-Type": "application/json",
|
|
89
|
+
},
|
|
90
|
+
body: JSON.stringify(req.body),
|
|
91
|
+
});
|
|
92
|
+
res
|
|
93
|
+
.status(r.status)
|
|
94
|
+
.set(Object.fromEntries(r.headers))
|
|
95
|
+
.send(await r.text());
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
app.listen(3000);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
- `OPENROUTER_SMALL_MODEL`: Specific model to use for `TEXT_SMALL`. Overrides `SMALL_MODEL` if set.
|
|
102
|
+
- `OPENROUTER_LARGE_MODEL`: Specific model to use for `TEXT_LARGE`. Overrides `LARGE_MODEL` if set.
|
|
103
|
+
- `OPENROUTER_IMAGE_MODEL`: Specific model to use for `IMAGE_DESCRIPTION`. Overrides `IMAGE_MODEL` if set.
|
|
104
|
+
- `OPENROUTER_IMAGE_GENERATION_MODEL`: Specific model to use for `IMAGE` generation. Overrides `IMAGE_GENERATION_MODEL` if set.
|
|
105
|
+
- `OPENROUTER_EMBEDDING_MODEL`: Specific model to use for `TEXT_EMBEDDING`. Overrides `EMBEDDING_MODEL` if set.
|
|
106
|
+
- `OPENROUTER_EMBEDDING_DIMENSIONS`: Number of dimensions for embedding vectors. Supported values: 256, 384, 512, 768, 1024, 1536, 2048, 3072. Defaults to 1536.
|
|
107
|
+
- `OPENROUTER_AUTO_CLEANUP_IMAGES`: Whether to automatically delete generated images after 30 seconds (default: "false"). Set to "true" to enable auto-cleanup.
|
|
108
|
+
- `SMALL_MODEL`: Fallback model for small tasks (default: "google/gemini-2.0-flash-001"). Used if `OPENROUTER_SMALL_MODEL` is not set.
|
|
109
|
+
- `LARGE_MODEL`: Fallback model for large tasks (default: "openai/gpt-5.1-nano"). Used if `OPENROUTER_LARGE_MODEL` is not set.
|
|
110
|
+
- `IMAGE_MODEL`: Fallback model for image analysis (default: "x-ai/grok-2-vision-1212"). Used if `OPENROUTER_IMAGE_MODEL` is not set.
|
|
111
|
+
- `IMAGE_GENERATION_MODEL`: Fallback model for image generation (default: "google/gemini-2.5-flash-image-preview"). Used if `OPENROUTER_IMAGE_GENERATION_MODEL` is not set.
|
|
112
|
+
- `EMBEDDING_MODEL`: Fallback model for text embeddings (default: "openai/text-embedding-3-small"). Used if `OPENROUTER_EMBEDDING_MODEL` is not set.
|
|
113
|
+
- `EMBEDDING_DIMENSIONS`: Fallback dimension setting for embeddings (default: "1536"). Used if `OPENROUTER_EMBEDDING_DIMENSIONS` is not set.
|
|
114
|
+
|
|
115
|
+
## Provided Models
|
|
116
|
+
|
|
117
|
+
The plugin currently provides these model types:
|
|
118
|
+
|
|
119
|
+
- `TEXT_SMALL`: Optimized for fast, cost-effective text generation using the configured small model. Supports `tools`, `toolChoice`, and `responseSchema` for structured output via native tool calling.
|
|
120
|
+
- `TEXT_LARGE`: For more complex text generation tasks requiring larger models, using the configured large model. Supports `tools`, `toolChoice`, and `responseSchema` for structured output via native tool calling.
|
|
121
|
+
- `IMAGE_DESCRIPTION`: Analyzes images and provides descriptive text and titles, using the configured image model.
|
|
122
|
+
- `IMAGE`: Generates images from text prompts using the configured image generation model (e.g., Gemini 2.5 Flash Image Preview).
|
|
123
|
+
- `TEXT_EMBEDDING`: Generates vector embeddings for text input, supporting configurable dimensions from 256 to 3072, using the configured embedding model.
|
|
124
|
+
|
|
125
|
+
_Note: Audio Transcription is not currently implemented in this specific OpenRouter plugin._
|
package/auto-enable.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Auto-enable check for @elizaos/plugin-openrouter.
|
|
2
|
+
//
|
|
3
|
+
// Plugin manifest entry-point — referenced by package.json's
|
|
4
|
+
// `elizaos.plugin.autoEnableModule`. Keep this module light: env reads only,
|
|
5
|
+
// no service init, no transitive imports of the full plugin runtime. The
|
|
6
|
+
// auto-enable engine loads dozens of these per boot.
|
|
7
|
+
import type { PluginAutoEnableContext } from "@elizaos/core";
|
|
8
|
+
|
|
9
|
+
const ENV_KEYS = ["OPENROUTER_API_KEY"] as const;
|
|
10
|
+
|
|
11
|
+
/** Enable when an OpenRouter API key is present. */
|
|
12
|
+
export function shouldEnable(ctx: PluginAutoEnableContext): boolean {
|
|
13
|
+
return ENV_KEYS.some((k) => {
|
|
14
|
+
const v = ctx.env[k];
|
|
15
|
+
return typeof v === "string" && v.trim() !== "";
|
|
16
|
+
});
|
|
17
|
+
}
|