Claude API / OpenAI API Basics
Call LLM APIs confidently: requests and responses, messages, parameters, streaming, tool use, errors and retries, cost, security and testing, with the real Anthropic and OpenAI SDKs run against a local stand-in server.
Syllabus
How LLM APIs Work
- What an LLM API Is
- API Keys, Environment Variables and Safe Setup
- A Raw HTTP Call: What the SDK Does for You
- Anthropic and OpenAI Side by Side
Messages, Parameters and Output
- Your First Call With Each SDK
- Roles, System Prompts and Conversation History
- Parameters: max_tokens, Temperature, Top-p, Stop
- Structured Output and Validating Replies
Streaming Responses
Tool Use (Function Calling)
- How Tool Use Works
- A Complete Tool Loop With the Anthropic SDK
- A Complete Tool Loop With the OpenAI SDK
- Designing and Securing Tools
Reliability: Errors, Retries and Limits
- Error Types and Which to Retry
- Exponential Backoff With Jitter
- Rate Limits, Concurrency and Timeouts
- Fallbacks and Graceful Degradation
Cost, Tokens and Performance
- Tokens, Pricing and Estimating Cost
- Tracking Usage and Setting Budgets
- Reducing Cost and Latency: Caching, Batching, Model Choice
Security, Testing and Production
- Protecting Keys and Logs
- Treating Model Output and Inputs as Untrusted
- Privacy, Data Handling and Compliance
- Testing Your Integration With a Stand-In Server