Claude API Anthropic ka official interface hai jiske through aap Claude AI ko apni applications, websites, aur automations mein integrate kar sakte ho. Yeh guide tumhe zero se pehli working API call tak le jaayegi — no prior API experience required. Python aur JavaScript dono examples included hain.
Claude API Kya Hai?
Claude.ai ek web interface hai — browser mein kholo aur chat karo. Lekin agar tum Claude ko apne product mein use karna chahte ho — apni website, app, chatbot, ya automation tool mein — to tumhe Claude API chahiye.
API ek "door" hai jo tumhare code ko Claude ke saath communicate karne deta hai. Tum ek request bhejte ho (jaise ek message), Claude process karta hai, aur response wapas aata hai — programmatically, real time mein.
| Feature | Claude.ai (Web) | Claude API |
|---|---|---|
| Usage | Browser mein manually | Code se programmatically |
| Automation | ❌ Manual only | ✅ Fully automated |
| Custom Integration | ❌ Not possible | ✅ Any app/platform |
| Pricing | Monthly subscription | Pay per token (usage-based) |
| Best For | Personal use | Building products |
API Key Setup Karo
Anthropic Console Account Banao
console.anthropic.com par jaao. Email se signup karo. New accounts ko free API credits milte hain testing ke liye.
API Key Generate Karo
Console mein "API Keys" section mein jaao. "Create Key" click karo. Key ko copy karo — yeh ek baar hi dikhti hai. Safely save karo.
Key Ko Environment Variable Mein Store Karo
Key ko apne code mein directly paste mat karo. Environment variable use karo:.env file mein: ANTHROPIC_API_KEY=sk-ant-...
⚠️ Security Warning: API key ko kabhi GitHub ya public code mein push mat karo. Agar accidental exposure ho, turant Console mein jaake key revoke karo aur naya banao.
Python Integration — First API Call
Pehle Anthropic Python SDK install karo:
TerminalAb pehli API call karo:
PythonSystem prompt ke saath (Claude ko custom role dene ke liye):
Python — With System PromptMulti-turn conversation (chat history ke saath):
Python — Multi-turn ChatJavaScript Integration
TerminalKey Concepts — Samajhna Zaroori Hai
Models
Anthropic ke paas teen main models hain Claude 4 family mein:
| Model | Speed | Cost | Best For |
|---|---|---|---|
| claude-haiku-4-5 | ⚡ Fastest | 💚 Cheapest | Simple tasks, high volume |
| claude-sonnet-4-6 | 🏃 Fast | 💛 Mid-range | Most production use cases |
| claude-opus-4-6 | 🧠 Slower | 🔴 Premium | Complex reasoning, research |
Tokens
Claude text ko "tokens" mein process karta hai — roughly 1 token ≈ ¾ of an English word. API charges input tokens + output tokens ke liye. max_tokens parameter se aap control kar sakte ho kitna long response aaye.
System Prompt
System prompt ek hidden instruction hai jo Claude ka role define karta hai. Yeh user ko nahi dikhti — sirf Claude ko instructions deta hai. Iska proper use production-grade AI apps ki foundation hai.
Temperature
Temperature (0-1) creativity control karta hai. 0 = deterministic, consistent responses (best for factual tasks). 1 = more creative, varied responses (best for creative writing). Default 1 hai.
Best Practices for Production
✅ Error Handling: API calls fail ho sakti hain. Always try-catch use karo aur retry logic implement karo for rate limit errors.
✅ Rate Limits: Anthropic har account ke liye rate limits set karta hai. High-volume apps ke liye batching implement karo aur delays add karo.
✅ Cost Monitoring: Console mein usage dashboard monitor karo. Unexpected costs avoid karne ke liye max_tokens reasonable set karo aur unnecessary API calls reduce karo.
✅ Streaming: Long responses ke liye streaming use karo — user ko type karte hue response dikh sake, wait nahi karna padega complete response ke liye.


