pi-coralbricks-provider 1.0.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 +227 -0
- package/custom-models.json +1 -0
- package/deprecated-models.json +1 -0
- package/index.ts +599 -0
- package/models.json +133 -0
- package/package.json +59 -0
- package/patch.json +1 -0
- package/scripts/probe-stream-fix.ts +62 -0
- package/scripts/update-models.js +572 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
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,227 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# 🪸 pi-coralbricks-provider
|
|
4
|
+
|
|
5
|
+
**GLM 5.2/5.3, Kimi K3 & GPT-OSS 120B through [Coral Bricks](https://www.coralbricks.ai)**
|
|
6
|
+
|
|
7
|
+
_A [pi](https://github.com/earendil-works/pi-coding-agent) provider extension for Coral's OpenAI-compatible inference gateway — up to **1M context** on open models._
|
|
8
|
+
|
|
9
|
+
[](https://github.com/earendil-works/pi-coding-agent)
|
|
10
|
+
[](https://www.npmjs.com/package/pi-coralbricks-provider)
|
|
11
|
+
[](./LICENSE)
|
|
12
|
+
[](https://github.com/synthetic-lab/synbad)
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
- **4 reasoning models** from Coral's DynamoDB-backed live catalog — GLM 5.2 FP4, GLM 5.3 FP4, Kimi K3, and GPT-OSS 120B
|
|
21
|
+
- **1M token context** on GLM and Kimi, with vision (image input) on Kimi K3
|
|
22
|
+
- **OpenAI-compatible API** — standard `/v1/chat/completions`, streaming, and tool calling
|
|
23
|
+
- **Per-family thinking levels** — zai-style `thinking` control for GLM (including a *real* off switch), `reasoning_effort` for Kimi K3 and GPT-OSS
|
|
24
|
+
- **Accurate cost tracking** — pricing mirrors Coral's published rates, and cached reads are **$0 on every model**, so pi's computed cost matches Coral's own `usage.cost` to the token
|
|
25
|
+
- **Self-healing model sync** — stale-while-revalidate from the authenticated `/v1/models` (or the unauthenticated [public catalog](https://www.coralbricks.ai/api/public/models) before auth), hot-swapped at session start
|
|
26
|
+
- **Streaming repair** — transparently fixes Coral's gpt-oss tool-call delta index fragmentation so streamed tool calls always accumulate correctly
|
|
27
|
+
- **synbad-validated** — [synbad](https://github.com/synthetic-lab/synbad) tool-calling and reasoning-parsing evals pass 15/15 on GLM 5.2, GLM 5.3, and Kimi K3 in both unary and streaming modes
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
### Option 1: Using `pi install` (Recommended)
|
|
32
|
+
|
|
33
|
+
Install directly from GitHub:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pi install https://github.com/monotykamary/pi-coralbricks-provider
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
or from npm:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pi install npm:pi-coralbricks-provider
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Then set your API key and run pi:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Recommended: add to auth.json
|
|
49
|
+
# See Authentication section below
|
|
50
|
+
|
|
51
|
+
# Or set as environment variable
|
|
52
|
+
export CORALBRICKS_API_KEY=cb_your-key-here
|
|
53
|
+
|
|
54
|
+
pi
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Option 2: Manual Clone
|
|
58
|
+
|
|
59
|
+
1. Clone this repository:
|
|
60
|
+
```bash
|
|
61
|
+
git clone https://github.com/monotykamary/pi-coralbricks-provider.git
|
|
62
|
+
cd pi-coralbricks-provider
|
|
63
|
+
bun install
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
2. Set your Coral API key:
|
|
67
|
+
```bash
|
|
68
|
+
# Recommended: add to auth.json
|
|
69
|
+
# See Authentication section below
|
|
70
|
+
|
|
71
|
+
# Or set as environment variable
|
|
72
|
+
export CORALBRICKS_API_KEY=cb_your-key-here
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
3. Run pi with the extension:
|
|
76
|
+
```bash
|
|
77
|
+
pi -e /path/to/pi-coralbricks-provider
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Available Models
|
|
81
|
+
|
|
82
|
+
| Model | Context | Vision | Reasoning | Input $/M | Cache Read $/M | Output $/M |
|
|
83
|
+
|-------|---------|--------|-----------|-----------|-----------------|------------|
|
|
84
|
+
| GLM 5.2 FP4 | 1.0M | ❌ | ✅ | $1.12 | — | $4.40 |
|
|
85
|
+
| GLM 5.3 FP4 | 1.0M | ❌ | ✅ | $1.12 | — | $4.40 |
|
|
86
|
+
| GPT-OSS 120B | 131K | ❌ | ✅ | $0.12 | — | $0.60 |
|
|
87
|
+
| Kimi K3 | 1.0M | ✅ | ✅ | $3.00 | — | $15.00 |
|
|
88
|
+
|
|
89
|
+
*Costs are per million tokens. Cache Read shows — because Coral bills cached input at **$0** on every model. Prices subject to change — check [Coral's live catalog](https://www.coralbricks.ai/api/public/models).*
|
|
90
|
+
|
|
91
|
+
## Usage
|
|
92
|
+
|
|
93
|
+
After loading the extension, use the `/model` command in pi to select your preferred model:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
/model coralbricks glm-5.3-fp4
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Or start pi directly with a Coral model:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
pi -e /path/to/pi-coralbricks-provider --model coralbricks/kimi-k3:high
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Thinking levels attach to the model id with `:<level>` — e.g. `:low`, `:high`, `:max`, or `:off` (GLM only).
|
|
106
|
+
|
|
107
|
+
## Authentication
|
|
108
|
+
|
|
109
|
+
The Coral API key can be configured in multiple ways (resolved in this order):
|
|
110
|
+
|
|
111
|
+
1. **`auth.json`** (recommended) — Add to `~/.pi/agent/auth.json`:
|
|
112
|
+
```json
|
|
113
|
+
{ "coralbricks": { "type": "api_key", "key": "cb_your-key" } }
|
|
114
|
+
```
|
|
115
|
+
The `key` field supports literal values, env var names, and shell commands (prefix with `!`).
|
|
116
|
+
2. **Runtime override** — Use the `--api-key` CLI flag
|
|
117
|
+
3. **Environment variable** — Set `CORALBRICKS_API_KEY`
|
|
118
|
+
|
|
119
|
+
With [localterm](https://www.npmjs.com/package/localterm), store it once and it's exposed everywhere:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
localterm secret set coralbricks_api_key
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
> Coral Inference is currently in a design-partner program — mint keys at [coralbricks.ai/api-keys](https://www.coralbricks.ai/api-keys). Newly-minted keys may take ~30 seconds to be honored, and `403 access_denied` means the account isn't on the allowlist yet.
|
|
126
|
+
|
|
127
|
+
## Thinking Levels
|
|
128
|
+
|
|
129
|
+
Verified against the live gateway:
|
|
130
|
+
|
|
131
|
+
| Model | Format | off | low | medium | high | max |
|
|
132
|
+
|-------|--------|-----|-----|--------|------|-----|
|
|
133
|
+
| GLM 5.2 FP4 | `thinking: {type}` + `reasoning_effort` | ✅ | — | ✅ | ✅ | ✅ |
|
|
134
|
+
| GLM 5.3 FP4 | `thinking: {type}` + `reasoning_effort` | ✅ | ✅ | — | ✅ | ✅ |
|
|
135
|
+
| Kimi K3 | `reasoning_effort` | — | ✅ | — | ✅ | ✅ |
|
|
136
|
+
| GPT-OSS 120B | `reasoning_effort` | — | ✅ | ✅ | ✅ | — |
|
|
137
|
+
|
|
138
|
+
- **GLM** accepts zai-style `thinking: {type: "disabled"}` on Coral — pi's *off* level genuinely disables thinking (the upstream Z.ai API does not, so this differs from the canonical Z.ai map).
|
|
139
|
+
- **Kimi K3** always thinks: `reasoning_effort: "none"` is accepted but doesn't disable reasoning, so *off* is intentionally not offered. Assistant replays include `reasoning_content`.
|
|
140
|
+
- **GPT-OSS** exposes the standard low/medium/high reasoning efforts; reasoning arrives in `reasoning_content`.
|
|
141
|
+
- Coral streams a duplicate `reasoning` field alongside `reasoning_content`; pi dedupes these automatically.
|
|
142
|
+
|
|
143
|
+
## Compat Settings
|
|
144
|
+
|
|
145
|
+
Coral's gateway follows the OpenAI Chat Completions API:
|
|
146
|
+
|
|
147
|
+
- **`supportsStore: false`** / **`supportsDeveloperRole: false`** — all models; Coral serves open models on the classic roles.
|
|
148
|
+
- **`maxTokensField: "max_tokens"`** — all models.
|
|
149
|
+
- **`thinkingFormat: "zai"`** — GLM 5.2/5.3: `thinking: {type: "enabled"|"disabled"}` toggles reasoning, `reasoning_effort` picks the depth.
|
|
150
|
+
- **`thinkingFormat: "openai"`** — Kimi K3 and GPT-OSS 120B: `reasoning_effort` drives thinking depth.
|
|
151
|
+
- **`supportsStrictMode: false`** — Kimi K3 (no strict JSON-schema tool definitions).
|
|
152
|
+
- **`requiresReasoningContentOnAssistantMessages: true`** — Kimi K3.
|
|
153
|
+
|
|
154
|
+
### Streaming Tool-Call Repair
|
|
155
|
+
|
|
156
|
+
On the raw wire, Coral occasionally emits a streamed tool call's final arguments fragment on a **new delta index** instead of continuing the existing one (`"index": 1` mid-call), which fragments the call under any spec-compliant accumulator. Observed on gpt-oss-120b; GLM and Kimi streams are correct.
|
|
157
|
+
|
|
158
|
+
This extension's `streamSimple` pipes SSE responses through a repair stream that rewrites id-less, name-less tool-call deltas claiming a fresh index onto the last real call's index. Deltas that do carry an id/name (new calls, parallel calls) pass through untouched, and streams that are already correct are byte-identical. Verify against a live model:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
CORALBRICKS_API_KEY=cb_... bun run scripts/probe-stream-fix.ts [model-id]
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Patch Overrides & Custom Models
|
|
165
|
+
|
|
166
|
+
- **`patch.json`** — per-model overrides applied on top of `models.json` (reasoning flags, pricing corrections, compat settings, thinking level maps). Currently empty — the curated defaults match the live API.
|
|
167
|
+
- **`custom-models.json`** — full model definitions for models Coral doesn't list. Merged after patch.
|
|
168
|
+
|
|
169
|
+
Merge order: `[live|cache|embedded] → patch.json → custom-models.json`
|
|
170
|
+
|
|
171
|
+
## Inference-Quality Testing
|
|
172
|
+
|
|
173
|
+
Validated with [synbad](https://github.com/synthetic-lab/synbad) — Synthetic's tool-calling and reasoning-parsing eval suite for LLM inference providers (`--count 1`, `--reasoning-effort high`, 15 evals per run):
|
|
174
|
+
|
|
175
|
+
| Model | Unary | Stream | Notes |
|
|
176
|
+
|-------|-------|--------|-------|
|
|
177
|
+
| GLM 5.2 FP4 | 15/15 ✅ | 15/15 ✅ | |
|
|
178
|
+
| GLM 5.3 FP4 | 15/15 ✅ | 15/15 ✅ | |
|
|
179
|
+
| Kimi K3 | 15/15 ✅ | 15/15 ✅ | |
|
|
180
|
+
| GPT-OSS 120B | 14/15 ⚠️ | 10–11/15 ❌ raw | repaired in-extension (see above) |
|
|
181
|
+
|
|
182
|
+
The remaining gpt-oss quirk is model-side: it answers "Paris and London" with a single batched tool call even when `parallel_tool_calls: true` — not a gateway bug.
|
|
183
|
+
|
|
184
|
+
Reproduce:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
CORALBRICKS_API_KEY=cb_... node ../synbad/dist/source/index.js eval \
|
|
188
|
+
--env-var CORALBRICKS_API_KEY \
|
|
189
|
+
--base-url https://inference.coralbricks.ai/v1 \
|
|
190
|
+
--model glm-5.3-fp4 --count 1 --reasoning-effort high
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Updating Models
|
|
194
|
+
|
|
195
|
+
Run the update script to fetch the latest models from Coral's API:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
export CORALBRICKS_API_KEY=cb_your-key
|
|
199
|
+
node scripts/update-models.js
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
This will:
|
|
203
|
+
1. Fetch models from `https://inference.coralbricks.ai/v1/models` (falls back to the unauthenticated [public catalog](https://www.coralbricks.ai/api/public/models) without a key)
|
|
204
|
+
2. Preserve existing model data (pricing, compat, thinking maps) for known models
|
|
205
|
+
3. Apply overrides from `patch.json`
|
|
206
|
+
4. Update `models.json` and the README model table
|
|
207
|
+
|
|
208
|
+
To regenerate just the README model table from local data — no API key needed:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
node scripts/update-models.js --readme-only
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Troubleshooting
|
|
215
|
+
|
|
216
|
+
| Symptom | Meaning |
|
|
217
|
+
|---------|---------|
|
|
218
|
+
| `403 access_denied` | Account not on the Coral Inference allowlist yet |
|
|
219
|
+
| `404 model_not_accepted` | Model id not enabled for your key |
|
|
220
|
+
| `401 invalid_api_key` | Re-mint at [coralbricks.ai/api-keys](https://www.coralbricks.ai/api-keys); fresh keys take ~30s to activate |
|
|
221
|
+
| `429 rate_limit_exceeded` | Per-key rate limit — retry with backoff |
|
|
222
|
+
| `502 upstream_error` / `503 backend_unconfigured` | Transient — retry |
|
|
223
|
+
| `504 timeout` | Sync request waited too long; re-issue smaller or use Coral's background Responses API |
|
|
224
|
+
|
|
225
|
+
## License
|
|
226
|
+
|
|
227
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|