build: token-monitor v0.1.0 — modular LLM API quota visibility

Implements modular provider probing with two distinct header schemas:
- Teams direct (unified schema): 5h/7d utilization floats, status, reset countdown
- Shelley proxy (classic schema): token/request counts + Exedev-Gateway-Cost (USD/call)
- api-ateam: reports no billing data (confirmed non-existent by recon)

Key: uses claude-haiku-4-5-20251001 for minimal probe calls (1 token).
Rate-limit headers present on ALL responses (200 and 429).

113/113 tests passing.

Built from Face recon (trentuna/a-team#91) — live header capture confirmed
unified schema with utilization floats replaces old per-count schema.
This commit is contained in:
Hannibal Smith 2026-04-04 17:01:05 +00:00
parent 760049a25e
commit 07a544c50d
Signed by: hannibal
GPG key ID: 6EB37F7E6190AF1C
10 changed files with 1093 additions and 1 deletions

View file

@ -0,0 +1,75 @@
/**
* anthropic-api.js api-ateam (pay-per-use, api03 keys)
*
* Anthropic's REST API does not expose billing or quota data via any endpoint
* (confirmed by recon, issue trentuna/a-team#91). This module reports that
* billing data is unavailable always. Key validity could be confirmed with
* a real HTTP call, but for monitoring purposes the static result is authoritative.
*/
import { getSeverity } from '../report.js';
/**
* Return the static api-ateam status object.
* Synchronous no HTTP call needed because no billing API exists.
* @returns {Object}
*/
export function getApiAteamStatus() {
return {
type: 'api-direct',
status: 'no_billing_data',
message: 'Anthropic API does not expose billing/quota via REST. Key validity not checked.',
severity: getSeverity({ type: 'api-direct' }),
};
}
/**
* Probe the api-ateam provider.
* Makes a minimal call to confirm key validity, but always reports no billing data.
* @param {string} providerName
* @param {string} baseUrl
* @param {string} apiKey
* @returns {Promise<Object>}
*/
export async function probeApiProvider(providerName, baseUrl, apiKey) {
try {
const response = await fetch(`${baseUrl}/v1/messages`, {
method: 'POST',
headers: {
'x-api-key': apiKey,
'anthropic-version': '2023-06-01',
'content-type': 'application/json',
},
body: JSON.stringify({
model: 'claude-haiku-4-5-20251001',
max_tokens: 1,
messages: [{ role: 'user', content: 'Hi' }],
}),
});
if (response.status === 401) {
return {
type: 'api-direct',
status: 'invalid_key',
message: 'Invalid API key (401)',
severity: 'unknown',
};
}
// No billing endpoint exists — always report no_billing_data
return {
type: 'api-direct',
status: 'no_billing_data',
message: 'Anthropic API does not expose billing/quota via REST. Key appears valid.',
http_status: response.status,
severity: 'unknown',
};
} catch (err) {
return {
type: 'api-direct',
status: 'error',
message: err.message,
severity: 'unknown',
};
}
}