Other AV widgets can call Claude programmatically via the proxy at /api/claude on the AV server (port 8770).
POST /api/claude
| Param | Type | Default | Description |
|---|---|---|---|
model | string | claude-haiku-4-5-20251001 | Model ID (see models below) |
messages | array | required | Array of {role, content} objects |
max_tokens | number | 1024 | Max output tokens |
system | string | none | System prompt |
temperature | number | API default | 0.0 - 1.0 |
Costs shown as API rate and Max rate (20x multiplier for Claude Max $200/mo plan).
| Model ID | Tier | Input $/M tok | Output $/M tok | Input (Max 20x) | Output (Max 20x) |
|---|---|---|---|---|---|
claude-opus-4-6 | Opus | $15.00 | $75.00 | $300 | $1,500 |
claude-sonnet-4-6 | Sonnet | $3.00 | $15.00 | $60 | $300 |
claude-haiku-4-5-20251001 | Haiku | $0.80 | $4.00 | $16 | $80 |
Raw Anthropic Messages API response. Key fields:
{
"id": "msg_...",
"model": "claude-haiku-4-5-20251001",
"content": [{ "type": "text", "text": "..." }],
"usage": {
"input_tokens": 16,
"output_tokens": 42
},
"stop_reason": "end_turn"
}
// Detect proxy prefix (handles coder proxy URLs and srcdoc iframes)
const API_BASE = (() => {
let path = location.pathname;
if (path === '/' || location.href.includes('about:srcdoc')) {
try { path = parent.location.pathname; } catch {}
}
const m = path.match(/^(\/proxy\/\d+)\//);
return m ? m[1] : '';
})();
async function askClaude(prompt, model = 'claude-haiku-4-5-20251001') {
const res = await fetch(API_BASE + '/api/claude', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model,
max_tokens: 1024,
messages: [{ role: 'user', content: prompt }],
}),
});
const data = await res.json();
if (data.error) throw new Error(data.error);
return {
text: data.content?.[0]?.text || '',
inputTokens: data.usage?.input_tokens || 0,
outputTokens: data.usage?.output_tokens || 0,
model: data.model,
};
}
const PRICING = {
'claude-opus-4-6': { input: 15.00, output: 75.00 },
'claude-sonnet-4-6': { input: 3.00, output: 15.00 },
'claude-haiku-4-5-20251001': { input: 0.80, output: 4.00 },
};
function calcCost(model, inputTok, outputTok) {
const p = PRICING[model];
return (inputTok * p.input + outputTok * p.output) / 1_000_000;
}