SynfraCore
Synfracore
Start Learning
Navigation

Academies

Platform

RoadmapsLabsCertificationsInterviewPYQsAI AssistantCareer
Start Learning Free🗺️ Learning Roadmaps

LLM EngineeringCheatsheets

Quick reference — commands, syntax, and patterns

✍️
Written by senior engineers. Reviewed for technical accuracy.· Updated 2025 · SynfraCore LLM Engineering Team
Expert Content

LLM Engineering Cheatsheet

API Quick Reference

OpenAI

python
from openai import OpenAI
client = OpenAI()

# Chat
resp = client.chat.completions.create(
    model="gpt-4o",           # gpt-4o-mini for cheap, o1 for reasoning
    messages=[{"role": "system", "content": "..."}, {"role": "user", "content": "..."}],
    temperature=0.3, max_tokens=1000
)
text = resp.choices[0].message.content
tokens = resp.usage.total_tokens

# Embed
emb = client.embeddings.create(model="text-embedding-3-small", input="text")
vector = emb.data[0].embedding  # 1536-dim list

Anthropic Claude

python
import anthropic
client = anthropic.Anthropic()
msg = client.messages.create(
    model="claude-3-5-sonnet-20241022", max_tokens=1024,
    system="...", messages=[{"role": "user", "content": "..."}]
)
print(msg.content[0].text)

Model Selection

TaskModelCost

|------|-------|------|

Simple Q&Agpt-4o-miniCheapest
Complex reasoninggpt-4oMedium
Long doc analysisClaude Sonnet (200K)Medium
Deep reasoningo1, o3Most expensive
Local/privateLlama 3.1 via OllamaFree
Embeddingstext-embedding-3-smallVery 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

StrategyChunk SizeOverlapBest For

|----------|-----------|---------|---------|

Fixed512 tokens50Dense prose
SemanticParagraph0Structured docs
Recursive1000 chars100General purpose
Sentence1-5 sentences1Q&A

RAG Quality Metrics (RAGAS)

MetricGoodDescription

|--------|------|-------------|

Faithfulness> 0.9Answer grounded in context
Answer Relevancy> 0.85Answer addresses question
Context Recall> 0.8Relevant docs retrieved
Context Precision> 0.7Retrieved docs are useful

Common Errors

ErrorFix

|-------|-----|

429 Rate limitExponential backoff: 1s, 2s, 4s, 8s + jitter
Context too longTruncate chunks, reduce system prompt
HallucinationAdd RAG context, lower temperature
Slow responseUse mini model, enable streaming, cache
Empty outputIncrease max_tokens, check stop sequences

Ollama Local Setup

bash
curl https://ollama.ai/install.sh | sh
ollama pull llama3.1        # 4.7 GB
ollama pull nomic-embed-text # embeddings

# Use like OpenAI
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
Share:
Join our Community
Daily tips, job alerts, interview help — join engineers learning together
Also Worth Exploring
← Back to all LLM Engineering modules
CertificationNotes