LLM Engineering Cheatsheet
API Quick Reference
OpenAI
Anthropic Claude
Model Selection
| Task | Model | Cost |
|---|
|------|-------|------|
| Simple Q&A | gpt-4o-mini | Cheapest |
|---|---|---|
| Complex reasoning | gpt-4o | Medium |
| Long doc analysis | Claude Sonnet (200K) | Medium |
| Deep reasoning | o1, o3 | Most expensive |
| Local/private | Llama 3.1 via Ollama | Free |
| Embeddings | text-embedding-3-small | Very cheap |
Token Math
•1 token ≈ 0.75 words
•gpt-4o-mini: $0.15/M input, $0.60/M output
•gpt-4o: $2.50/M input, $10/M output
•text-embedding-3-small: $0.02/M tokens
Chunking Reference
| Strategy | Chunk Size | Overlap | Best For |
|---|
|----------|-----------|---------|---------|
| Fixed | 512 tokens | 50 | Dense prose |
|---|---|---|---|
| Semantic | Paragraph | 0 | Structured docs |
| Recursive | 1000 chars | 100 | General purpose |
| Sentence | 1-5 sentences | 1 | Q&A |
RAG Quality Metrics (RAGAS)
| Metric | Good | Description |
|---|
|--------|------|-------------|
| Faithfulness | > 0.9 | Answer grounded in context |
|---|---|---|
| Answer Relevancy | > 0.85 | Answer addresses question |
| Context Recall | > 0.8 | Relevant docs retrieved |
| Context Precision | > 0.7 | Retrieved docs are useful |
Common Errors
| Error | Fix |
|---|
|-------|-----|
| 429 Rate limit | Exponential backoff: 1s, 2s, 4s, 8s + jitter |
|---|---|
| Context too long | Truncate chunks, reduce system prompt |
| Hallucination | Add RAG context, lower temperature |
| Slow response | Use mini model, enable streaming, cache |
| Empty output | Increase max_tokens, check stop sequences |

