Wiring in the Claude API

LLM Call

Part of: Build a RAG System

Time to connect the pipeline to a real model. You've retrieved chunks and assembled a grounded prompt. The last step is sending it to Claude and getting the answer back. The Messages API call The Anthropic SDK uses one endpoint for this: client.messages.create. You pass a model, a token budget, and your messages list, the same list your pipeline built. A few things to lock in: - The key comes from the environment , never hardcoded, os.environ["ANTHROPIC API KEY"]. A leaked key in source is a real incident, not a style nit. - messages is a list of role/content dicts. Your RAG prompt goes in as a single user message. That's exactly what build messages produced last lesson. - The answer is in response.content[0].text. The response is a list of content blocks; for a plain text answer you read the first block's text. Put a system prompt to work You can sharpen grounding by moving the rules into a system prompt, the model treats system instructions as higher-authority standing rules, separate from the per-question context: System for the rules, user message for the context and question. Clean separation. The whole system, one function Wrap it all up and you have a document Q&A tool: That

Challenge: Wire the Grounded Claude Request