Skip to content

feat(providers/llm): real Anthropic Claude adapter with prompt caching #13

@wesleysimplicio

Description

@wesleysimplicio

Context

ClaudeProvider at lib/providers/llm.ts:42-46 is a mock. Per AGENTS.md routing, Claude is the default for orchestration, script, compliance, humanization (and fallback for caption / translation).

Goal

Replace the mock with a real adapter against the Anthropic API. Use the claude-api skill guidance: import @anthropic-ai/sdk, default to the latest model (claude-opus-4-7 for high-quality / claude-sonnet-4-6 for cost-sensitive), enable prompt caching on the system message and brand context.

Acceptance criteria

  • npm i @anthropic-ai/sdk
  • ClaudeProvider.generate calls the Messages API with the correct model per task (compliance / script → opus-4-7; caption / humanization → sonnet-4-6)
  • Prompt caching enabled (cache_control: { type: 'ephemeral' }) on stable preamble blocks: brand voice, persona, channel rules
  • Returns GenerationResult with real tokens, cost_usd, latency_ms
  • Reads ANTHROPIC_API_KEY from process env (loaded by CLI)
  • Retry on transient errors (5xx / network), respect 429 with backoff
  • Timeout 60s for short tasks, 180s for script
  • Skipped when DRY_RUN=true (mock variant used; see #provider-mocks)
  • E2E spec with mocked HTTP layer asserts payload shape (system prompt + cache control + messages)

Files

  • lib/providers/llm.ts:42-46 (ClaudeProvider)
  • package.json (new dep)

Depends on

  • #provider-mocks-isolation (cleaner ground)
  • #env-loader (env loaded consistently — see Sprint 0 acceptance)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions