What is an LLM?
A Large Language Model (LLM) is a machine learning model trained on huge text corpora. It can:
- generate text, code, translations
- answer questions in natural language
- analyze, summarize and classify documents
- write and debug code
The most popular models
| Model | Vendor | Context | Strengths |
|---|---|---|---|
| Claude Opus 4 | Anthropic | 200k tokens | Reasoning, code, safety |
| Claude Sonnet 4 | Anthropic | 200k tokens | Price/quality balance |
| GPT-4o | OpenAI | 128k tokens | Multimodality |
| Gemini 1.5 Pro | 1M tokens | Long context | |
| Llama 3.1 | Meta | 128k tokens | Open-source |
Calling Claude through the API
Python
import anthropic
client = anthropic.Anthropic(api_key="sk-ant-...")
message = client.messages.create(
model="claude-opus-4-5",
max_tokens=1024,
system="You are a PHP and Symfony expert.",
messages=[
{"role": "user", "content": "Explain in 3 points what Dependency Injection is"}
]
)
print(message.content[0].text)
PHP (Guzzle)
use GuzzleHttp\Client;
$client = new Client(['base_uri' => 'https://api.anthropic.com']);
$response = $client->post('/v1/messages', [
'headers' => [
'x-api-key' => $_ENV['ANTHROPIC_API_KEY'],
'anthropic-version' => '2023-06-01',
'content-type' => 'application/json',
],
'json' => [
'model' => 'claude-opus-4-5',
'max_tokens' => 1024,
'messages' => [
['role' => 'user', 'content' => 'Write a PHP function to validate a VAT number']
],
],
]);
$data = json_decode($response->getBody(), true);
echo $data['content'][0]['text'];
Streaming responses
Instead of waiting for the whole response, you can stream token by token:
with client.messages.stream(
model="claude-opus-4-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Write an essay about PHP"}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
Common use cases in web projects
- SEO description generation — paste the title and content, get a meta description
- Code assistant — code review, error explanations
- Support chatbot — answers questions based on an FAQ
- Sentiment analysis — comment classification
- Translations — better than Google Translate for technical text
Costs: Claude Sonnet is ~$3/1M input tokens. A typical blog article is about 1500 tokens. Reasonable for assistants, expensive when processing millions of documents.
Good practices
- always validate and sanitize user input
- never paste sensitive data (passwords, API keys) into the prompt
- set
max_tokens— without a limit the model can generate very long responses - use the
systemprompt to assign a role and constraints to the model