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.
75 lines
2.1 KiB
JavaScript
75 lines
2.1 KiB
JavaScript
/**
|
|
* 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',
|
|
};
|
|
}
|
|
}
|