Tra cứu và viết mã gọi Claude API
claude-api
Tài liệu tham chiếu để viết mã dùng Claude qua SDK chính thức: mã mô hình, giá, tham số, streaming, công cụ, bộ nhớ đệm, đếm token và chuyển sang mô hình mới.
Tải miễn phí. Theo dõi Skilnexa một lần là mở khoá mọi lượt tải trên web.
Nó là gì
Bộ hướng dẫn tra cứu để viết mã gọi Claude API qua SDK chính thức: chọn model, cách gọi tool, streaming, cache, agent. Dành cho lập trình viên, không dành cho người chỉ dùng chatbot.
Hoạt động ra sao
AI quét tệp xem có dấu hiệu nhà cung cấp khác (như OpenAI) không; nếu có thì dừng và hỏi bạn. Rồi nó nhận ra ngôn ngữ dự án, đọc đúng tệp tài liệu theo việc cần làm và viết mã bằng SDK chính thức. Mặc định dùng claude-opus-4-8, streaming; không đoán tên hàm.
Ví dụ ứng dụng
- Tình huống
- Lập trình viên có ứng dụng Python và muốn thêm chức năng tóm tắt email dài bằng Claude.
- Bạn đưa vào
- Tệp Python hiện có, yêu cầu tóm tắt, không có dấu hiệu OpenAI trong dự án.
- Bạn nhận được
- Mã dùng SDK anthropic với model claude-opus-4-8, bật streaming cho đầu vào dài, lấy kết quả bằng get_final_message.
Ví dụ minh họa theo quy trình trong tài liệu gốc, chưa phải kết quả thử chạy.
Dùng khi nào
Khi lập trình viên thêm tính năng trò chuyện Claude vào ứng dụng của mình.
Các phần chính trong hướng dẫn
- Trước khi bắt đầu
- Yêu cầu đầu ra
- Mặc định
- Các lệnh con
- Nhận diện ngôn ngữ
- Chọn bề mặt API phù hợp
- Có nên xây agent không?
- Các mô hình hiện tại
Xem mô tả gốc của tác giả (tiếng Anh)
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER — read BEFORE opening the target file; don't skip because it "looks like a one-liner" — whenever: the prompt names Claude/Anthropic in any form (Claude, Anthropic, Fable, Opus, Sonnet, Haiku, `anthropic`, `@anthropic-ai`, `claude-*`, `us.anthropic.*`, `[1m]`); the user asks about an LLM (pricing/model choice/limits/caching) — never answer from memory; OR the task is LLM-shaped with provider unstated (agent/MCP/tool-definition/multi-agent/RAG/LLM-judge/computer-use; generate/summarize/extract/classify/rewrite/converse over NL; debugging refusals/cutoffs/streaming/tool-calls/tokens). SKIP only when another provider is being worked on (overrides all triggers): OpenAI/GPT/Gemini/Llama/Mistral/Cohere/Ollama named in the query; OR `grep -rE 'openai|langchain_openai|google.generativeai|genai|mistralai|cohere|ollama'` over the project hits (run this grep FIRST if no provider named — don't Read the file).
Chi tiết tính năng
- When the user asks you to add, modify, or implement a Claude feature, your code must call Claude through one of:
- The official Anthropic SDK for the project's language (
anthropic,@anthropic-ai/sdk,com.anthropic.*, etc.). This is the default whenever a supported SDK exists for the project. - Raw HTTP (
curl,requests,fetch,httpx, etc.) — only when the user explicitly asks for cURL/REST/raw HTTP, the project is a shell/cURL project, or the language has no official SDK. - Never mix the two — don't reach for
requests/fetchin a Python or TypeScript project just because it feels lighter. Never fall back to OpenAI-compatible shims. - Never guess SDK usage. Function names, class names, namespaces, method signatures, and import paths must come from explicit documentation — either the
{lang}/files in this skill or the official SDK repositories or documentation links listed inshared/live-sources.md. If the binding you need is not explicitly documented in the skill files, WebFetch the relevant SDK repo fromshared/live-sources.mdbefore writing code. Do not infer Ruby/Java/Go/PHP/C# APIs from cURL shapes or from another language's SDK. - If WebFetch or repository access fails (network restricted, timeouts, clone blocked): do not keep retrying — write code from the patterns and namespace/package tables in the
{lang}/file, run the compiler or interpreter on it, and iterate on the error output. For statically-typed SDKs (C#, Java, Go) a compile-fix loop against local errors reaches working code faster than blocked network research.
Ví dụ yêu cầu
- Use WebFetch to get the latest documentation when:
- User asks for "latest" or "current" information
- Cached data seems incorrect
- User asks about features not covered here
- Live documentation URLs are in
shared/live-sources.md.
Cùng nhóm Kỹ thuật phần mềm
- Kiểm tra và sửa lỗi truy cập cho người khuyết tậtQuét mã web theo WCAG 2.2 mức A và AA, tự sửa lỗi, kiểm độ tương phản màu, lập báo cáo; chạy được cho React, Vue, Angular, Svelte, HTML.
- Rà soát mã khắt khe qua ba góc nhìnXem lại thay đổi mã bằng ba nhân vật khó tính: kẻ phá hoại, người mới vào và kiểm toán bảo mật; mỗi người phải tìm ra lỗi, kết luận BLOCK, CONCERNS hoặc CLEAN.
- Điều quân đoàn agent làm việc lớn song songTriển khai hai lớp agent song song cho việc lớn như viết lại nhiều tệp, di chuyển hàng loạt, kiểm tra toàn mã nguồn, có an toàn git và kiểm tra trước khi chạy.
- Thiết kế hệ nhiều agent phối hợpChọn kiểu điều phối (giám sát, bầy đàn, dây chuyền), tạo khai báo công cụ cho agent và phân tích nhật ký chạy về chi phí, độ trễ, lỗi.
- Chạy bầy agent xử lý dữ liệu hàng loạtTriển khai nhiều agent phụ xử lý song song các việc dữ liệu như 1000 tài liệu, phân tích bộ dữ liệu, tạo nội dung số lượng lớn; có theo dõi tiến độ và khắc phục lỗi.
- Dựng đội agent cho quy trình kinh doanhHỏi về quy trình công việc rồi tạo cấu hình đội agent gồm vai trò, quyền dùng công cụ, cách liên lạc và quy tắc bàn giao.
Phần giải thích do Skilnexa viết sau khi đọc toàn bộ tài liệu gốc của tác giả và đã đối chiếu lại với nội dung gốc. Chưa phải kết quả thử chạy, nên hãy thử bằng dữ liệu giả trước khi dùng cho việc thật.