Learn > Claude > Building with the Claude API

Building with the Claude API

Xây app Claude thật từ đầu: API & streaming, prompt engineering + evaluation, RAG, tool use/MCP, agentic workflows.

  • Khoá developer ~8 giờ của Anthropic Academy: từ gọi Claude API cơ bản đến prompt evaluation, tool use, RAG, MCP và agentic workflows.
  • Ghi chú tiếng Việt chia 7 phần theo đúng module khoá — mỗi phần một trang riêng, link ngay đầu trang này.
  • Đề thi thử 589 câu tự biên soạn (chấm điểm, đáp án + giải thích từng câu) ở tab Đề thi thử.

TL;DRBuilding with the Claude API là khoá developer ~8 giờ của Anthropic Academy về tích hợp Claude qua API: gọi API & streaming, prompt engineering + evaluation, tool use, RAG, MCP và agentic workflows. Đây là ghi chú tiếng Việt đầy đủ 7 phần theo đúng module khoá (thuật ngữ giữ nguyên tiếng Anh kèm chú thích), kèm đề thi thử 589 câu có chấm điểm và giải thích từng câu ở tab "Đề thi thử".

Lộ trình ghi chú — 7 phần

  1. Claude API cơ bản — vòng đời request, multi-turn, streaming & structured data vòng đời request 5 bước, vì sao cần server riêng, API key, hội thoại multi-turn, system prompt, temperature, response streaming và ép Claude trả structured data.
  2. Prompt engineering & evaluation với Claude — workflow 5 bước, graders, 4 kỹ thuật phân biệt prompt engineering vs prompt evaluation, workflow eval 5 bước, tự sinh test dataset, model/code graders và 4 kỹ thuật viết prompt chuẩn Anthropic.
  3. Tool use với Claude API — JSON Schema, multi-block messages, conversation loop cho Claude gọi hàm qua tool schema (JSON Schema), multi-block messages, tool result, conversation loop nhiều tool, streaming tool use và built-in tools (text editor, web search).
  4. RAG với Claude — text chunking, embeddings, BM25 & hybrid search pipeline RAG 6 bước — 4 chiến lược text chunking, semantic search với embeddings và cosine similarity, class VectorIndex, BM25 và hybrid search với Reciprocal Rank Fusion.
  5. Claude API nâng cao — extended thinking, vision, PDF, citations, prompt caching extended thinking ("giấy nháp" của Claude), vision (đưa ảnh), PDF processing, citations trích nguồn, prompt caching giảm chi phí và Files API + code execution.
  6. MCP trong Claude API — dựng server FastMCP, client, resources & prompts Model Context Protocol — communication flow client ↔ server, dựng MCP server bằng FastMCP, test bằng MCP Inspector, viết MCP client, expose resources và prompts.
  7. Claude Code & agentic workflows — parallelization, chaining, routing, agents Claude Code (4 nhóm tool, CLAUDE.md, cắm MCP), 3 workflow pattern (parallelization · chaining · routing), agents với abstract tools, environment inspection và cách chọn workflow vs agent.

Áp dụng thực tế: phần RAG và evaluation ở khoá này là bản nền tảng, gọn hơn nhiều so với RAG tôi đã dựng cho doanh nghiệp từ trước đó. Pipeline thực chiến (chunking → embedding → hybrid search → eval) tôi viết ở Pipeline custom RAG từ chunking đến eval; còn cách chặn ảo giác bằng review nhiều lớp nằm ở RAG zero-hallucination cho doanh nghiệp.

Học 7 phần này theo thứ tự nào — góc nhìn triển khai

Khoá xếp 7 phần theo độ khó tăng dần, nhưng khi đưa Claude vào sản phẩm thật, mức độ quan trọng của từng phần không đi theo đúng thứ tự đó. Đây là cách tôi ưu tiên khi làm ở vai trò Delivery Manager / System Architect — không phải để học nhanh hơn, mà để không trả giá ở production:

  • Nền bắt buộc — phần 1–2 (API cơ bản & prompt evaluation). Phần lớn lỗi "AI trả sai" ngoài production không đến từ model yếu, mà từ việc không có bộ eval để đo prompt đang tốt hay tệ. Học kỹ workflow evaluation 5 bước ở phần 2 có giá trị hơn thuộc lòng 20 mẹo prompt: có eval thì mỗi lần chỉnh prompt/đổi model đều biết mình đang tiến hay lùi.
  • Xương sống của app doanh nghiệp — phần 3–4 (tool use & RAG). Đây là chỗ Claude chạm dữ liệu thật, cũng là chỗ rủi ro nhất. Cạm bẫy hay gặp nhất tôi thấy: nhảy thẳng vào vector search trước khi có eval, để rồi khi kết quả kém thì không biết nên chỉnh chunking, embedding hay retrieval. Phần RAG ở khoá là bản nền tảng; pipeline thực chiến và cách chặn ảo giác tôi để ở hai bài blog dẫn ngay trên.
  • Tối ưu chi phí & độ tin — phần 5 (nâng cao). Với hệ thống nhiều lượt gọi lặp ngữ cảnh, prompt caching thường là đòn giảm chi phí lớn nhất mà không đụng tới logic; còn citations là điều kiện để khách chịu tin số liệu Claude đưa ra thay vì coi là "máy chém".
  • Mở rộng & tự động hoá — phần 6–7 (MCP & agentic workflow). Rất mạnh nhưng cũng dễ over-engineer nhất. Nguyên tắc của tôi: giữ luồng cố định (chaining/routing) càng lâu càng tốt, chỉ chuyển sang agent tự quyết đường đi khi bài toán thật sự có nhánh không đoán trước được — agent khó test và khó ước lượng chi phí hơn workflow rất nhiều.

Khi nào dùng kỹ thuật nào

Bảng tra nhanh để chọn đúng kỹ thuật cho từng bài toán — đọc kèm chi tiết ở trang từng phần:

Kỹ thuật Giải quyết vấn đề gì Nên dùng khi Chưa cần khi
Prompt + streaming (P1) Gọi Claude, hội thoại multi-turn, ép structured output Nền tảng bắt buộc của mọi app
Prompt evaluation (P2) Đo chất lượng prompt một cách khách quan Trước khi lên production; khi cần so nhiều prompt/model Prototype chạy một lần rồi bỏ
Tool use (P3) Cho Claude gọi hàm/API, lấy dữ liệu động Cần thao tác hệ thống ngoài (query, tính toán, gọi API) Chỉ sinh văn bản thuần
RAG (P4) Trả lời dựa trên tài liệu riêng, giảm bịa Knowledge base lớn hoặc đổi thường xuyên Kiến thức nhỏ, nhét thẳng vào prompt là đủ
Nâng cao (P5): caching, vision, PDF, citations Giảm chi phí, đọc ảnh/PDF, trích nguồn Nhiều lượt gọi trùng ngữ cảnh; cần dẫn nguồn App đơn giản, ít lượt gọi
MCP (P6) Chuẩn hoá kết nối tool/data để tái dùng Nhiều app/agent dùng chung một bộ tool Một app với vài tool cố định
Agentic workflow (P7) Claude tự lập kế hoạch nhiều bước Bài toán có nhánh không đoán trước được Luồng cố định → dùng workflow/chaining

Tài liệu & Chứng chỉ liên quan

Học tiếp trong cụm: nắm nền tảng trước ở Claude 101AI Capabilities and Limitations; xem toàn bộ lộ trình và đích chứng chỉ ở Lộ trình học Claude cùng Chứng chỉ Claude / CCA-F.

Thông tin bản quyền & Nguồn

Nguồn: Building with the Claude API (Anthropic Academy) — Copyright Anthropic. Phần đề thi thử cho khoá này nằm ở tab "Đề thi thử".

Câu hỏi thường gặp

Khoá Building with the Claude API dạy gì?
Khoá developer ~8 giờ của Anthropic Academy về tích hợp Claude qua API: gọi API & streaming, prompt engineering + evaluation, tool use, RAG, Model Context Protocol (MCP) và agentic workflows. Ghi chú tiếng Việt ở đây chia thành 7 phần theo đúng module khoá, mỗi phần một trang riêng (link ngay đầu trang này).
Cần biết gì trước khi học khoá này?
Nên có nền Python cơ bản (hàm, dict, async) và đã nắm Claude ở mức người dùng (xem khoá Claude 101). Khoá đi từ gọi API đơn giản nên không cần kinh nghiệm machine learning; các thuật ngữ được giữ nguyên tiếng Anh kèm chú thích tiếng Việt để bám sát tài liệu gốc và đề thi.
Học khoá này có mất phí không?
Không. Course Certificate trên Anthropic Academy miễn phí, chỉ cần đăng ký bằng email; ghi chú và đề thi thử tiếng Việt ở trang này cũng miễn phí. Chi phí duy nhất phát sinh là tiền gọi Claude API khi bạn tự chạy code thực hành.
Đề thi thử khoá này ở đâu và có bao nhiêu câu?
Ngay trên trang tổng quan này, ở tab "Đề thi thử": bộ 589 câu tự biên soạn bám sát đề chứng chỉ thật, có chấm điểm, đáp án và giải thích từng câu. Đề trải đủ 7 phần: API cơ bản, prompt evaluation, tool use, RAG, tính năng nâng cao, MCP và agentic workflows.
Bộ ghi chú 7 phần này khác gì so với xem khoá gốc?
Đây là ghi chú tiếng Việt cô đọng toàn khoá kèm góc nhìn triển khai thực tế của một Delivery Manager/System Architect — dùng để ôn nhanh và tra cứu, không thay thế việc làm hands-on trong khoá gốc. Mỗi phần tóm tắt khái niệm cốt lõi, liệt kê "từ khoá cần thuộc" cho đề thi và có các đoạn áp dụng thực chiến.

Đề thi thử (589 câu)

Đề thi thử tự biên soạn, bám sát đề thi chứng chỉ thật — trích 20 câu đầu dưới đây. Bản tương tác — chấm điểm, đáp án & giải thích từng câu — nằm ở tab “Đề thi thử” trên trang.

  1. Request Lifecycle Why should you NOT call the Anthropic API directly from client-side code (web or mobile app)?

    • A. Client devices are too slow to handle the response
    • B. API requests require a secret API key that would be exposed and could be extracted for unauthorized use
    • C. The Anthropic API only accepts requests from servers, never browsers
    • D. Client code cannot parse JSON responses
  2. Request Lifecycle What is the correct order of the five-step request flow?

    • A. Request to Anthropic API → Request to server → Model processing → Response to client → Response to server
    • B. Request to server → Request to Anthropic API → Model processing → Response to server → Response to client
    • C. Model processing → Request to server → Request to Anthropic API → Response to client → Response to server
    • D. Request to server → Model processing → Request to Anthropic API → Response to server → Response to client
  3. Request Lifecycle (Select all that apply) Which fields are required in every request to the Claude API? (chọn nhiều đáp án)

    • A. API Key
    • B. Model
    • C. Messages
    • D. Max Tokens
  4. Request Lifecycle When a request is built, where is the user's input text placed?

    • A. Directly in the "model" field
    • B. Inside a "user" message, which is then placed in a list of messages
    • C. In the "max_tokens" parameter
    • D. In the API key header
  5. Request Lifecycle What does the "max_tokens" field control?

    • A. The maximum size of the input prompt
    • B. The maximum number of tokens Claude is allowed to generate
    • C. The number of SDK retries
    • D. The model's context window size
  6. Request Lifecycle (Select all that apply) For which languages does Anthropic provide official SDKs? (chọn nhiều đáp án)

    • A. Python
    • B. TypeScript / JavaScript
    • C. Go
    • D. Ruby
  7. Model Processing What is the correct order of the four stages Claude uses to process a request?

    • A. Embedding → Tokenization → Generation → Contextualization
    • B. Tokenization → Embedding → Contextualization → Generation
    • C. Tokenization → Contextualization → Embedding → Generation
    • D. Generation → Embedding → Contextualization → Tokenization
  8. Model Processing What is a "token"?

    • A. A secret key used to authenticate the request
    • B. A small chunk of text — a whole word, part of a word, a space, or a symbol
    • C. A complete sentence
    • D. A unit of GPU compute time
  9. Model Processing What does an embedding represent?

    • A. The final answer text
    • B. A list of numbers capturing all the possible meanings of a token and its semantic relationships
    • C. The number of tokens remaining before max_tokens
    • D. A compressed copy of the API key
  10. Model Processing What is the purpose of the contextualization stage?

    • A. To split the input into tokens
    • B. To refine each embedding based on surrounding words to determine the most likely meaning in context
    • C. To count input and output tokens for billing
    • D. To pick the final word with the highest probability
  11. Model Processing During generation, does Claude always pick the single highest-probability next word?

    • A. Yes, it always selects the most probable word
    • B. No — it mixes probability with controlled randomness to produce natural, varied responses
    • C. No — it always picks the least probable word
    • D. Yes, unless extended thinking is enabled
  12. Model Processing (Select all that apply) Which conditions cause Claude to stop generating? (chọn nhiều đáp án)

    • A. It reaches the max_tokens limit
    • B. It generates a natural end-of-sequence token
    • C. It encounters a predefined stop sequence
    • D. The user's API key expires mid-response
  13. API Response (Select all that apply) Which fields are included in the structured API response? (chọn nhiều đáp án)

    • A. Message — the generated text
    • B. Usage — count of input and output tokens
    • C. Stop Reason — why generation ended
    • D. API Key — echoed back for verification
  14. API Response Your application receives a response and the output text appears cut off mid-sentence. Which stop reason most likely explains this?

    • A. Natural end-of-sequence
    • B. The max_tokens limit was reached
    • C. A connector was disconnected
    • D. The embedding stage failed
  15. API Keys & Setup When you create a new API key in the Anthropic Console, how many times is the key value displayed?

    • A. Once — copy it immediately; if you lose it, delete the key and create a new one
    • B. It is always visible in the dashboard
    • C. Three times, then it is hidden
    • D. It is emailed to you so you can retrieve it anytime
  16. API Keys & Setup What is the recommended way to store your API key in a Python project?

    • A. Hardcode it as a string literal in the notebook
    • B. In a .env file (loaded via python-dotenv), with .env added to .gitignore
    • C. In a public GitHub Gist for easy access
    • D. As a comment at the top of each file
  17. API Keys & Setup Given `client = Anthropic()` with no arguments, where does the client get the API key?

    • A. It prompts the user to type it in
    • B. From the ANTHROPIC_API_KEY environment variable
    • C. From a hardcoded default key
    • D. It generates a new key automatically
  18. Making a Request Which three parameters does client.messages.create() require?

    • A. api_key, model, temperature
    • B. model, max_tokens, messages
    • C. model, system, stop_sequences
    • D. prompt, max_tokens, role
  19. Making a Request Which statement about max_tokens is correct?

    • A. It is a target length Claude tries to reach
    • B. It is a safety limit — Claude writes what it deems appropriate and stops only if it hits the maximum
    • C. It sets the minimum number of tokens Claude must generate
    • D. It controls the size of the input prompt
  20. Making a Request (Select all that apply) Which are valid roles for a message in the messages list? (chọn nhiều đáp án)

    • A. user — content you send to Claude (written by humans)
    • B. assistant — responses Claude has generated
    • C. system — the operating system log
    • D. developer — the code author

…và 569 câu nữa trong bản đề thi thử đầy đủ (589 câu) — mở tab “Đề thi thử” trên trang để làm toàn bộ, có chấm điểm & giải thích.