ClaudeApi AV Widget

Test Claude models directly from AV. Each card fires a real API request and shows timing + token cost.
Image Namer (Vision) claude-haiku-4-5-20251001
Drop an image here or click to select Sends image to Haiku to suggest a descriptive filename
Drop an image to get started...

Reusable API Reference

Other AV widgets can call Claude programmatically via the proxy at /api/claude on the AV server (port 8770).

Endpoint

POST /api/claude

Request Body (JSON)

ParamTypeDefaultDescription
modelstringclaude-haiku-4-5-20251001Model ID (see models below)
messagesarrayrequiredArray of {role, content} objects
max_tokensnumber1024Max output tokens
systemstringnoneSystem prompt
temperaturenumberAPI default0.0 - 1.0

Available Models

Costs shown as API rate and Max rate (20x multiplier for Claude Max $200/mo plan).

Model IDTierInput $/M tokOutput $/M tokInput (Max 20x)Output (Max 20x)
claude-opus-4-6Opus$15.00$75.00$300$1,500
claude-sonnet-4-6Sonnet$3.00$15.00$60$300
claude-haiku-4-5-20251001Haiku$0.80$4.00$16$80

Response (JSON)

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"
}

JavaScript Example (from another AV widget)

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

Cost Calculation

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;
}