anthropic-sdk-pro
Anthropic SDK Pro -- Claude AI for Next.js 16
When to Use
Trigger on any mention of: anthropic, claude, claude api, ai sdk, ai enhancement, streaming response, tool use, function calling, prompt engineering, token counting, ai rate limit, claude sonnet, claude haiku.
Reference Files
Load the relevant file(s) from references/ based on the task:
| File | Content |
|---|---|
setup.md |
SDK compatibility (version matrix, runtime), client init, env vars, API key security |
messages-api.md |
Single/multi-turn requests, system prompts, parameters, response structure, models + pricing |
streaming.md |
stream: true vs .stream(), SSE route handlers, client-side consumption, event types |
tool-use.md |
JSON Schema tools, agentic loop, Zod-based tools, tool choice, structured output via tools |
error-handling.md |
SDK error classes, auto retry behavior, timeout config, request ID tracking, Route Handler pattern |
token-management.md |
Token estimation, countTokens() API, usage tracking, max_tokens strategies, optimization tips |
cv-ai-patterns.md |
6 prompts: bullet enhance, summary, skills, translate, ATS, cover letter + endpoint table |
errors.md |
18 error entries (AI-001 through AI-018) with exact messages, causes, and fixes |
rate-limiting.md |
Tier tables (1-4), RPM/ITPM/OTPM limits, cache-aware ITPM, app-level usage tracking |
cost-optimization.md |
Model selection, prompt caching (90% savings), Batch API (50% off), CViet cost estimates |
vercel-ai-sdk.md |
@ai-sdk/anthropic, streamText, generateText, useChat, structured output, extended thinking |
security.md |
Input sanitization, prompt injection prevention, output validation, defense-in-depth |
prompt-engineering.md |
General principles, system prompt template, temperature guide, output format, structured output |
Error Quick Lookup
| ID | Error | Fix |
|---|---|---|
| AI-001 | Error objects crossing RSC boundary | Catch + return { error: e.message } plain object |
| AI-002 | 401 authentication_error | Check ANTHROPIC_API_KEY env var |
| AI-003 | 429 rate_limit_error | Implement exponential backoff, check tier limits |
| AI-004 | 529 overloaded_error | Retry with delay, SDK auto-retries 2x |
| AI-005 | 400 invalid_request_error | Validate all params before sending |
| AI-006 | Context length exceeded | Truncate input, use countTokens() before sending |
| AI-007 | Streaming timeout | Set maxDuration in route config, use stream: true |
| AI-008 | JSON parsing failure | Use regex extraction or structured outputs |
| AI-009 | Model not found | Use exact model ID: claude-sonnet-4-6 |
| AI-010 | Content policy violation | Review input, handle gracefully |
| AI-011 | Empty content response | Check stop_reason, increase max_tokens |
| AI-012 | TypeScript compilation errors | Pin SDK version, check changelog |
| AI-013 | Network connection error | Check connectivity, SDK auto-retries 2x |
| AI-014 | Non-streaming request too long | Use stream: true or increase timeout |
| AI-015 | Invalid API key format | Must start with sk-ant-api03-, regenerate key |
| AI-016 | Concurrent request limit | Queue requests, upgrade API tier |
| AI-017 | Output truncated | Increase max_tokens, check stop_reason |
| AI-018 | Prompt caching minimum size | Content must exceed 1024-4096 token threshold |
Key Patterns
CV Bullet Enhancement
// app/api/ai/enhance/route.ts
const response = await anthropic.messages.create({
model: 'claude-sonnet-4-6',
max_tokens: 1024,
system: 'You are an expert CV writer. Rewrite bullet points to be impactful and ATS-friendly.',
messages: [{ role: 'user', content: `Rewrite these bullets:\n${bullets.join('\n')}` }]
})
Streaming in Route Handler
export async function POST(req: Request) {
const stream = await anthropic.messages.stream({
model: 'claude-sonnet-4-6',
max_tokens: 1024,
messages: [{ role: 'user', content: prompt }]
})
return new Response(stream.toReadableStream())
}
Usage Tracking (Free/Pro Gating)
if (user.plan === 'FREE' && user.aiUsageThisMonth >= 3) {
return NextResponse.json({ error: 'AI limit reached' }, { status: 429 })
}
await db.user.update({ where: { id: user.id }, data: { aiUsageThisMonth: { increment: 1 } } })
More from clownnvd/claude-code-skills
prisma-better-auth-nextjs
Prisma 7 + Better Auth + Next.js App Router. Email/password, OAuth, 2FA, rate limiting, audit logging. Triggers: add auth, better auth, prisma auth, nextjs login, sign-up/sign-in, auth scaffold.
14ui-ux-pro-max
UI/UX design intelligence. 93 styles, 121 palettes, 81 font pairings, 35 charts, 79 components, 62 animations, 65 WCAG criteria, 46 responsive patterns, 46 dark mode rules, 60 design tokens, 13 stacks. Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check. Styles: glassmorphism, brutalism, neumorphism, bento, dark mode, view transitions, scroll-driven, container queries, AI-native, liquid glass, neo-minimalism, mesh gradient, geometric abstraction. Topics: color, accessibility, animation, layout, typography, spacing, shadow, gradient, responsive, dark mode, WCAG 2.2, design tokens, components, spring physics, kinetic typography, container queries, popover API, semantic tokens.
9stripe
Use when adding payments, billing, checkout, subscriptions, invoices, webhooks, customer portal, Stripe Connect, metered/usage billing, tax, fraud/Radar, pricing page, payment intents, refunds, coupons, promo codes, or any Stripe integration in Next.js. Triggers: stripe, payment, checkout, subscribe, billing, invoice, webhook, portal, connect, marketplace, payout, metered, usage-based, SaaS pricing, paywall, plan, tier.
8nextjs
Next.js 16 App Router patterns, proxy.ts, use cache, async APIs, 37 documented errors with fixes, ecosystem compatibility, postinstall patches.
8vercel-react-best-practices
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
8agent-browser
Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction.
7