kiro 0.1.34: each model shows Kiro's credit multiplier

01huadalang on Discord: "kiro 加上积分倍率消耗". Kiro's
List-Available-Models gives each model rateMultiplier with rateUnit
"Credit"; listModels now carries it as the model's rate, which magpie's
plugin host reads (rateOf) as Model.Rate, on the account's list and on the
config's model. A null, non-number, zero or negative multiplier, or a unit
other than Credit, gives no rate.

Values from a real Free account on 11-09 (origin KIRO_CLI and AI_EDITOR
answer the same, and kiro-cli chat --list-models shows the same
rate_multiplier): auto 1, claude-sonnet-4.5 1.3, claude-haiku-4.5 0.4,
deepseek-3.2 0.25, minimax-m2.5 0.25, minimax-m2.1 0.15, glm-5 0.5,
qwen3-coder-next 0.05. rate.test.mjs keeps sonnet's and the default
model's objects as Kiro sent them.

Usage is not multiplied again: the credits a request's meteringEvent
reports (usage.credit) already include the rate. One prompt cost 0.005349
on haiku and 0.017385 on sonnet, 3.25x, which is 1.3/0.4. The README says so.

Run on mote: packages/kiro bun test with HOME under the temp dir, 170 pass
0 fail; bun scripts/check.mjs kiro ok. Real run: listModels with kiro-cli's
sign-in returned all eight rates and runtimeModel carries them.
Broken by hand: without the rate in listModels both rate tests go red;
without the unit check the "no rate" test goes red.
Not tried: a Pro account's list (only Free); the rate in magpie's GUI. The
full root suite at this head was cut off when mote dropped mid-run
(connection closed by the host); it was not run to the end.
This commit is contained in:
yetone
2026-11-09 12:45:12 +08:00
parent c8125b92b5
commit 1aab125bf1
4 changed files with 81 additions and 6 deletions
+6 -3
View File
@@ -237,8 +237,10 @@ own search used instead.
The `config` hook declares `auto` (Kiro picks the model). Once signed in,
the `provider.models` hook replaces it with the account's own list from
`List-Available-Models`, with the default first. Each model carries its
context window, output limit and whether it takes images. Claude models
and Auto have the thinking variants.
context window, output limit and whether it takes images, and its credit
multiplier as `rate` (Kiro's `rateMultiplier` when `rateUnit` is `Credit`:
1.3 for claude-sonnet-4.5, 0.4 for claude-haiku-4.5), which magpie shows
beside the model. Claude models and Auto have the thinking variants.
## Usage in magpie
@@ -254,7 +256,8 @@ month's window counts against the overage cap (`overageCap`), which is the
month's whole limit; with it off, against the plan's credits.
Each request's cost is what Kiro's `meteringEvent`s say, in credits, summed
over the request (a web search's turns included). It goes on as
over the request (a web search's turns included). Kiro has already applied
the model's multiplier to it, so it isn't multiplied again. It goes on as
`usage.credit` in the last `message_delta`, or in the message's `usage`, for
magpie's ledger (yetone/magpie#4328). Kiro gives no token counts, so the
input is reckoned from how full the context is, and the cache is unknown
+22 -2
View File
@@ -782,6 +782,8 @@ function configModel(m) {
? { reasoning: true, variants: Object.fromEntries(Object.entries(BUDGETS).map(([k, b]) => [k, { thinking: { type: "enabled", budgetTokens: b } }])) }
: {}),
tool_call: true,
// magpie's own: the credit multiplier Kiro lists for the model
...(m.rate ? { rate: m.rate } : {}),
}
}
@@ -807,6 +809,8 @@ function runtimeModel(m) {
interleaved: false,
},
release_date: "",
// magpie's own: the credit multiplier Kiro lists for the model
...(m.rate ? { rate: m.rate } : {}),
variants: thinks(m.id) ? Object.fromEntries(Object.entries(BUDGETS).map(([k, b]) => [k, { thinking: { type: "enabled", budgetTokens: b } }])) : {},
}
}
@@ -831,6 +835,21 @@ async function keyModels(a) {
return out
}
// rateOf is the credits a model's request costs as a multiple, as Kiro's
// list says it (rateMultiplier with rateUnit "Credit": on 11-09 a Free
// account's list had auto 1, claude-sonnet-4.5 1.3, claude-haiku-4.5 0.4,
// glm-5 0.5, deepseek-3.2 and minimax-m2.5 0.25, minimax-m2.1 0.15 and
// qwen3-coder-next 0.05, which kiro-cli 2.x reads as its rate_multiplier).
// Nothing is the rate when Kiro gives none, or gives it in another unit.
// It is only shown: what a request cost is the meteringEvent's credits,
// which Kiro has already multiplied (the same prompt metered 0.00535 on
// claude-haiku-4.5 and 0.01739 on claude-sonnet-4.5, 0.4 to 1.3).
function rateOf(m) {
const n = m?.rateMultiplier
if (typeof n !== "number" || !Number.isFinite(n) || n <= 0) return undefined
return String(m.rateUnit ?? "").toLowerCase() === "credit" ? n : undefined
}
// listModels is List-Available-Models, the default first.
async function listModels(a) {
const out = a.tokenType === "API_KEY" ? await keyModels(a) : await managementCall(a.region, a, "List-Available-Models", { origin: "KIRO_CLI", profileArn: a.profile })
@@ -839,8 +858,9 @@ async function listModels(a) {
if (!m?.modelId) continue
let name = m.modelName
if (!name || name === m.modelId) name = m.modelId === "auto" ? "Auto" : m.modelId
const rate = rateOf(m)
const model = { id: m.modelId, name, context: m.tokenLimits?.maxInputTokens ?? 0, output: m.tokenLimits?.maxOutputTokens ?? 0,
images: (m.supportedInputTypes ?? []).some((t) => String(t).toUpperCase() === "IMAGE") }
images: (m.supportedInputTypes ?? []).some((t) => String(t).toUpperCase() === "IMAGE"), ...(rate ? { rate } : {}) }
if (m.modelId === out?.defaultModel?.modelId) list.unshift(model)
else list.push(model)
}
@@ -3133,4 +3153,4 @@ export async function KiroAuthPlugin({ client } = {}) {
}
// for tests
export const _internal = { generate, responsesBody, crMessages, crRefusal, features, FEATURES, featureKey, waitOf, timing, TRIES, refresh, usageOf, buildKiro, kiroBody, IMAGE_LIMIT, events, reply, failure, toolID, toolName, toolNames, thinking, nativeFields, listModels, contextFirst, configModel, runtimeModel, readCLI, readIDE, regionOf, planName, frames }
export const _internal = { generate, responsesBody, crMessages, crRefusal, features, FEATURES, featureKey, waitOf, timing, TRIES, refresh, usageOf, buildKiro, kiroBody, IMAGE_LIMIT, events, reply, failure, toolID, toolName, toolNames, thinking, nativeFields, listModels, rateOf, contextFirst, configModel, runtimeModel, readCLI, readIDE, regionOf, planName, frames }
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-kiro-auth",
"version": "0.1.33",
"version": "0.1.34",
"description": "Kiro subscriptions (Free, Pro, Pro+, Power) in OpenCode and magpie",
"type": "module",
"main": "./opencode.mjs",
+52
View File
@@ -0,0 +1,52 @@
import { test, expect } from "bun:test"
import { _internal } from "./index.mjs"
// Discord (01huadalang, 11-09): "kiro 加上积分倍率消耗". Kiro charges each
// model at its own credit rate and says it in List-Available-Models
// (rateMultiplier, rateUnit). The fixture is a Free account's answer on
// 11-09, byte for byte for claude-sonnet-4.5 and the default model; the
// other models keep only the fields this reads.
const SONNET = {"additionalModelRequestFieldsSchema":null,"availableOrigins":null,"consentDescription":null,"consentStatus":null,"description":"Claude Sonnet 4.5 model","disclaimers":null,"modelId":"claude-sonnet-4.5","modelName":"claude-sonnet-4.5","modelProvider":null,"promptCaching":{"maximumCacheCheckpointsPerRequest":4,"minimumTokensPerCacheCheckpoint":1024,"supportsPromptCaching":true},"rateMultiplier":1.3,"rateUnit":"Credit","refusalFallbackModels":null,"status":null,"supportedInputTypes":["TEXT","IMAGE"],"termsUrl":null,"tokenLimits":{"maxInputTokens":200000,"maxOutputTokens":64000}}
const DEFAULT = {"additionalModelRequestFieldsSchema":null,"availableOrigins":null,"consentDescription":null,"consentStatus":null,"description":null,"disclaimers":null,"modelId":"auto","modelName":null,"modelProvider":null,"promptCaching":null,"rateMultiplier":null,"rateUnit":null,"refusalFallbackModels":null,"status":null,"supportedInputTypes":null,"termsUrl":null,"tokenLimits":null}
const rated = (modelId, rateMultiplier, rateUnit = "Credit") => ({ modelId, modelName: modelId, rateMultiplier, rateUnit,
tokenLimits: { maxInputTokens: 200000, maxOutputTokens: 64000 } })
const MODELS = [rated("auto", 1), SONNET, rated("claude-haiku-4.5", 0.4), rated("deepseek-3.2", 0.25), rated("minimax-m2.5", 0.25),
rated("minimax-m2.1", 0.15), rated("glm-5", 0.5), rated("qwen3-coder-next", 0.05)]
const listed = async (models) => {
const was = globalThis.fetch
globalThis.fetch = async (input) => {
if (new URL(String(input)).pathname !== "/List-Available-Models") throw new Error("no network in tests")
return Response.json({ defaultModel: DEFAULT, models, nextToken: null })
}
try {
return await _internal.listModels({ region: "us-east-1", token: "t", tokenType: "", profile: "arn:aws:codewhisperer:us-east-1:1:profile/P" })
} finally {
globalThis.fetch = was
}
}
test("each model carries the credit multiplier Kiro lists for it", async () => {
const list = await listed(MODELS)
expect(Object.fromEntries(list.map((m) => [m.id, m.rate]))).toEqual({
auto: 1, "claude-sonnet-4.5": 1.3, "claude-haiku-4.5": 0.4, "deepseek-3.2": 0.25, "minimax-m2.5": 0.25,
"minimax-m2.1": 0.15, "glm-5": 0.5, "qwen3-coder-next": 0.05,
})
// magpie reads it as m.rate on the account's list and on the config's
const sonnet = list.find((m) => m.id === "claude-sonnet-4.5")
expect(_internal.runtimeModel(sonnet).rate).toBe(1.3)
expect(_internal.configModel(sonnet).rate).toBe(1.3)
})
test("no rate is shown where Kiro gives none, or gives it in another unit", async () => {
const list = await listed([{ ...SONNET, rateMultiplier: null, rateUnit: null }, rated("glm-5", 0.5, "Request"), rated("deepseek-3.2", "0.25"),
rated("minimax-m2.1", 0), rated("qwen3-coder-next", -1), rated("claude-haiku-4.5", 0.4, "CREDIT")])
for (const m of list) {
if (m.id === "claude-haiku-4.5") continue
expect(m.rate).toBeUndefined()
expect("rate" in _internal.runtimeModel(m)).toBe(false)
expect("rate" in _internal.configModel(m)).toBe(false)
}
// the unit's case is Kiro's to choose
expect(list.find((m) => m.id === "claude-haiku-4.5").rate).toBe(0.4)
})