import Anthropic from "@anthropic-ai/sdk";
const DEFAULT_MODEL = "claude-haiku-4-5";
const TOOL_NAME = "extract";
async function callAnthropic(opts, apiKey) {
  const client = new Anthropic({ apiKey });
  const model = opts.modelOverride ?? DEFAULT_MODEL;
  const start = Date.now();
  const response = await client.messages.create(
    {
      model,
      max_tokens: 2048,
      tools: [
        {
          name: TOOL_NAME,
          description: "Return the extracted fields as structured JSON.",
          input_schema: opts.jsonSchema
        }
      ],
      tool_choice: { type: "tool", name: TOOL_NAME },
      messages: [{ role: "user", content: opts.prompt }]
    },
    { signal: opts.signal }
  );
  const block = (response.content ?? []).find(
    (b) => b.type === "tool_use"
  );
  if (!block) {
    throw new Error("anthropic: no tool_use block in response");
  }
  return {
    values: block.input,
    provider: "anthropic",
    model: response.model ?? model,
    cached: false,
    latencyMs: Date.now() - start
  };
}
export {
  callAnthropic
};
//# sourceMappingURL=anthropic.js.map