/** * 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} */ 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', }; } }