magpie-blaze-api 0.0.0-stage → 0.1.0
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 +113 -2
- package/index.mjs +53 -0
- package/opencode.mjs +3 -0
- package/opencode2.mjs +634 -0
- package/package.json +60 -4
- package/src/constants.mjs +157 -0
- package/src/fetch.mjs +126 -0
- package/src/models.mjs +354 -0
- package/src/plugin.mjs +331 -0
- package/src/usage.mjs +337 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 suwupnil
|
|
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
CHANGED
|
@@ -1,3 +1,114 @@
|
|
|
1
|
-
#
|
|
1
|
+
# blaze-api-magpie
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A full-fledged provider plugin for [**magpie**](https://usemagpie.ai) and [**OpenCode**](https://opencode.ai) (compatible with both OpenCode 1.x and OpenCode 2.x) supporting [**BlazeAPI**](https://blazeapi.org) (`https://api.blazeapi.org/paid/v1`).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Multi-protocol native routing**:
|
|
8
|
+
- **Anthropic Messages** (`/paid/v1/messages` via `@ai-sdk/anthropic`) for paid/Tokens-V2 Claude models (`claude-opus-5-5`, `claude-sonnet-5-5`, `claude-sonnet-5`, `claude-opus-4.8`, `claude-haiku-4.5`, etc.), with `x-api-key` + `anthropic-version: 2023-06-01` headers and SSE streaming.
|
|
9
|
+
- **OpenAI Responses** (`/paid/v1/responses` via `@ai-sdk/openai`) for GPT-5+, o-series, and Codex models (`gpt-5.5`, `gpt-5.4`, `gpt-5.3-codex`, etc.).
|
|
10
|
+
- **OpenAI Chat Completions** (`/paid/v1/chat/completions` via `@ai-sdk/openai-compatible`) for Gemini, DeepSeek, Grok, Qwen, GLM, Kimi, MiniMax, `free/*` models, and Tavily search models (`tavily-search`, `tavily-extract`, `tavily-crawl`, `tavily-map`, `tavily-research`).
|
|
11
|
+
- **Live catalog discovery (`provider.models`)**:
|
|
12
|
+
- Fetches your live model list from `GET /paid/v1/models` with pricing (`cost.input`, `cost.output`, `cost.cache.read`), context/output token limits, vision modalities, reasoning variants (`low` / `medium` / `high`), `free: true` badges on `free/*` models, and `rate` multipliers on `tokv2/*` models.
|
|
13
|
+
- Automatically falls back to your last known per-account catalog on transient network/5xx errors without losing models, and marks `signIn: "expired"` on HTTP 401.
|
|
14
|
+
- **Usage & balance reporting (`auth.usage`)**:
|
|
15
|
+
- Reads `GET /paid/v1/usage` to surface your plan, PAYG balance, daily token allowance, RPM limits, Token Vault, Tokens V2, and Credits in Magpie's UI, `magpie quota`, and `GET /v1/magpie/quotas`.
|
|
16
|
+
- **Sign-in flows (`auth.methods`)**:
|
|
17
|
+
- **BlazeAPI Key**: quick native API key entry (`blaze-…`).
|
|
18
|
+
- **BlazeAPI Key (verify & configure)**: validates your key live against BlazeAPI, identifies your account/plan, and lets you choose catalog scope (`all`, `available`, or `free`) and an optional custom Base URL.
|
|
19
|
+
- **Smart error & routing handling**:
|
|
20
|
+
- Preserves `X-Magpie-Sign-In: kept` on HTTP `402` (`price_above_cap`), `403` (plan/model restriction), and `429` (rate/daily limit) so Magpie failover moves to the next account/model without falsely expiring your key.
|
|
21
|
+
- Optional `X-Blaze-Provider` routing header (`cheapest`, `fastest`, `best`, or comma-separated provider names such as `sirius,cosmos`).
|
|
22
|
+
- **Magpie + OpenCode 1.x + OpenCode 2.x compatible**:
|
|
23
|
+
- Exports `{ BlazeApiPlugin }` from `./opencode.mjs` (`main`) for Magpie and OpenCode 1.x, and `{ id, setup }` from `./opencode2.mjs` (`exports["."]`) for OpenCode 2.x.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
### In Magpie
|
|
28
|
+
|
|
29
|
+
From npm (searchable in Magpie's Discover → Plugins):
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
magpie plugin add magpie-blaze-api
|
|
33
|
+
magpie plugin login blazeapi
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
From GitHub:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
magpie plugin add github:suwupnil/blaze-api-magpie
|
|
40
|
+
magpie plugin login blazeapi
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
From a local clone:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
git clone https://github.com/suwupnil/magpie-blaze-api.git
|
|
47
|
+
magpie plugin add ./blaze-api-magpie
|
|
48
|
+
magpie plugin login blazeapi
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Check status, models, and quota:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
magpie plugin
|
|
55
|
+
magpie provider models blazeapi
|
|
56
|
+
magpie provider test blazeapi
|
|
57
|
+
magpie quota
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### In OpenCode
|
|
61
|
+
|
|
62
|
+
Add the plugin to your `opencode.json` (project or `~/.config/opencode/opencode.json`):
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"$schema": "https://opencode.ai/config.json",
|
|
67
|
+
"plugin": ["magpie-blazeapi-auth"]
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Then run `opencode auth login blazeapi` (or `opencode auth login` and select **BlazeAPI**).
|
|
72
|
+
|
|
73
|
+
## Plugin Options
|
|
74
|
+
|
|
75
|
+
In Magpie (`plugins.json` or `magpie plugin options <plugin-spec> '<json>'`), you can configure:
|
|
76
|
+
|
|
77
|
+
| Option | Default | Description |
|
|
78
|
+
| --- | --- | --- |
|
|
79
|
+
| `baseURL` | `"https://api.blazeapi.org/paid/v1"` | Custom BlazeAPI-compatible base URL. |
|
|
80
|
+
| `scope` | `"available"` | `"available"` (only models your current balance/plan can call), `"all"` (all chat models including PAYG models with `$0` balance), or `"free"` (only `free/*` models). |
|
|
81
|
+
| `protocol` | `"auto"` | `"auto"` (native Anthropic for Claude, Responses for GPT-5+/o-series/Codex, Chat Completions for the rest) or `"chat"` (force Chat Completions for all models). |
|
|
82
|
+
| `providerRouting` | `""` | Set to `"cheapest"`, `"fastest"`, `"best"`, or provider names (e.g. `"sirius,cosmos"`) to send `X-Blaze-Provider`. |
|
|
83
|
+
| `includeSearchModels` | `true` | Include Tavily search models (`tavily-*`). |
|
|
84
|
+
| `includeTokV2` | `true` | Include `tokv2/*` models. |
|
|
85
|
+
| `includeFree` | `true` | Include `free/*` models. |
|
|
86
|
+
| `includeUnavailable` | `false` | Include models currently marked `down` or globally unavailable. |
|
|
87
|
+
|
|
88
|
+
Example:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
magpie plugin options github:suwupnil/blaze-api-magpie '{"providerRouting":"cheapest","scope":"available"}'
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Development & Testing
|
|
95
|
+
|
|
96
|
+
Run syntax checks and unit/integration tests with Node.js (>= 20) or Bun:
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
npm run lint
|
|
100
|
+
npm test
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Test inside an isolated Magpie sandbox without touching your real configuration:
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
sb=$(mktemp -d)
|
|
107
|
+
m() { env HOME="$sb" XDG_CONFIG_HOME="$sb/.config" XDG_CACHE_HOME="$sb/.cache" MAGPIE_ADDR=127.0.0.1:3499 magpie "$@"; }
|
|
108
|
+
m plugin add . </dev/null
|
|
109
|
+
m plugin --json
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
MIT
|
package/index.mjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BLAZE_ICON_DATA_URI,
|
|
3
|
+
BLAZE_ICON_SVG,
|
|
4
|
+
DEFAULT_BASE_URL,
|
|
5
|
+
PROVIDER_ID,
|
|
6
|
+
PROVIDER_NAME,
|
|
7
|
+
SDK,
|
|
8
|
+
SEED_MODELS,
|
|
9
|
+
} from "./src/constants.mjs";
|
|
10
|
+
import { createBlazeFetch } from "./src/fetch.mjs";
|
|
11
|
+
import {
|
|
12
|
+
buildConfigModels,
|
|
13
|
+
fetchBlazeModels,
|
|
14
|
+
formatModelName,
|
|
15
|
+
isEligibleModel,
|
|
16
|
+
isReasoningModel,
|
|
17
|
+
normalizeBaseURL,
|
|
18
|
+
protocolForModel,
|
|
19
|
+
transformCatalogModels,
|
|
20
|
+
variantsFor,
|
|
21
|
+
} from "./src/models.mjs";
|
|
22
|
+
import { BlazeApiPlugin } from "./src/plugin.mjs";
|
|
23
|
+
import {
|
|
24
|
+
fetchBlazeUsage,
|
|
25
|
+
nextUtcMidnight,
|
|
26
|
+
parseUsagePayload,
|
|
27
|
+
} from "./src/usage.mjs";
|
|
28
|
+
|
|
29
|
+
export { BlazeApiPlugin };
|
|
30
|
+
export default BlazeApiPlugin;
|
|
31
|
+
|
|
32
|
+
export const _internal = {
|
|
33
|
+
PROVIDER_ID,
|
|
34
|
+
PROVIDER_NAME,
|
|
35
|
+
DEFAULT_BASE_URL,
|
|
36
|
+
SDK,
|
|
37
|
+
SEED_MODELS,
|
|
38
|
+
BLAZE_ICON_SVG,
|
|
39
|
+
BLAZE_ICON_DATA_URI,
|
|
40
|
+
normalizeBaseURL,
|
|
41
|
+
protocolForModel,
|
|
42
|
+
isReasoningModel,
|
|
43
|
+
variantsFor,
|
|
44
|
+
formatModelName,
|
|
45
|
+
isEligibleModel,
|
|
46
|
+
buildConfigModels,
|
|
47
|
+
transformCatalogModels,
|
|
48
|
+
fetchBlazeModels,
|
|
49
|
+
parseUsagePayload,
|
|
50
|
+
fetchBlazeUsage,
|
|
51
|
+
nextUtcMidnight,
|
|
52
|
+
createBlazeFetch,
|
|
53
|
+
};
|
package/opencode.mjs
ADDED