SSkilnexa
SkillKỹ thuật phần mềmHợp với: Lập trình viênMức: Kỹ thuật

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út theo dõi đang được chuẩn bị.
Link tải đang được chuẩn bị.

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

  1. Trước khi bắt đầu
  2. Yêu cầu đầu ra
  3. Mặc định
  4. Các lệnh con
  5. Nhận diện ngôn ngữ
  6. Chọn bề mặt API phù hợp
  7. Có nên xây agent không?
  8. 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/fetch in 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 in shared/live-sources.md. If the binding you need is not explicitly documented in the skill files, WebFetch the relevant SDK repo from shared/live-sources.md before 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

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.