📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Generative AI Engineering LLM APIs

LLM APIs

5 min read Quiz at the end
Integrate Anthropic Claude and OpenAI APIs — key parameters, response structure, and usage tracking.

LLM API Integration

# Anthropic Claude
import anthropic
client = anthropic.Anthropic(api_key='your-key')

response = client.messages.create(
    model='claude-opus-4-5',
    max_tokens=1024,
    system='You are a helpful assistant.',
    messages=[{'role':'user','content':'Explain RAG in 3 sentences.'}]
)
print(response.content[0].text)
print(response.usage)  # input_tokens, output_tokens

# OpenAI
from openai import OpenAI
client = OpenAI(api_key='your-key')
response = client.chat.completions.create(
    model='gpt-4o',
    messages=[
        {'role':'system','content':'You are a helpful assistant.'},
        {'role':'user','content':'Explain RAG in 3 sentences.'}
    ],
    temperature=0.3,
    max_tokens=500
)
print(response.choices[0].message.content)

# Key parameters
# temperature: 0-2 (randomness)
# max_tokens:  output length limit
# top_p:       nucleus sampling
# stop:        stop sequences
# stream:      token-by-token streaming
Topic Quiz · 2 questions

Test your understanding before moving on

1. Which parameter controls LLM output randomness?
💡 temperature controls randomness: 0 is deterministic, higher values produce more varied and creative outputs.
2. What does max_tokens limit?
💡 max_tokens sets the maximum number of tokens the model will generate in its response.