🌐 Detecting your location…

Claude API Tutorial 2026: Erstellen Sie KI-Apps mit Anthropic Claude

⏱️2 min read  ·  406 words
Claude API Tutorial 2026: Build AI Apps with Anthropic Claude

DasClaude-APIvon Anthropic ist eine der leistungsfähigsten KI-APIs im Jahr 2026. Claude Sonnet 4 bietet 200.000 Kontext, Vision, Werkzeugnutzung und schnelles Caching. Dieses Tutorial behandelt den ersten API-Aufruf über Produktions-KI-Funktionen.

Einrichtung

pip install anthropic
export ANTHROPIC_API_KEY=sk-ant-...your-key...

Erster API-Aufruf

import anthropic

client = anthropic.Anthropic()

message = client.messages.create(
    model='claude-sonnet-4-5',
    max_tokens=1024,
    messages=[
        {'role': 'user', 'content': 'Explain async/await in Python in 3 sentences.'}
    ]
)

print(message.content[0].text)

Multi-Turn-Chat

client = anthropic.Anthropic()
system = 'You are a senior Python developer. Be concise. Use code examples.'
history = []

def chat(user_msg: str) -> str:
    history.append({'role': 'user', 'content': user_msg})
    resp = client.messages.create(
        model='claude-sonnet-4-5',
        max_tokens=2048,
        system=system,
        messages=history
    )
    reply = resp.content[0].text
    history.append({'role': 'assistant', 'content': reply})
    return reply

print(chat('How do I read a CSV file?'))
print(chat('Now filter rows where age > 25'))

Streaming

with client.messages.stream(
    model='claude-sonnet-4-5',
    max_tokens=1024,
    messages=[{'role': 'user', 'content': 'Write a Python quicksort'}]
) as stream:
    for text in stream.text_stream:
        print(text, end='', flush=True)

Werkzeugverwendung (Funktionsaufruf)

tools = [{
    "name": "get_weather",
    "description": "Get current weather for a city",
    "input_schema": {
        "type": "object",
        "properties": {"city": {"type": "string"}},
        "required": ["city"]
    }
}]

response = client.messages.create(
    model='claude-sonnet-4-5',
    max_tokens=1024,
    tools=tools,
    messages=[{'role': 'user', 'content': 'What is the weather in Tokyo?'}]
)

if response.stop_reason == 'tool_use':
    for block in response.content:
        if block.type == 'tool_use':
            print(f'Tool: {block.name}, Input: {block.input}')

Sofortiges Caching (90 % Kostenreduzierung)

response = client.messages.create(
    model='claude-sonnet-4-5',
    max_tokens=1024,
    system=[{
        "type": "text",
        "text": very_long_system_prompt,
        "cache_control": {"type": "ephemeral"}
    }],
    messages=[{'role': 'user', 'content': user_question}]
)
print(f'Cache read: {response.usage.cache_read_input_tokens}')

Vision: Bilder analysieren

import base64
with open('screenshot.png', 'rb') as f:
    img = base64.standard_b64encode(f.read()).decode()

response = client.messages.create(
    model='claude-sonnet-4-5',
    max_tokens=1024,
    messages=[{'role': 'user', 'content': [
        {'type': 'image', 'source': {'type': 'base64', 'media_type': 'image/png', 'data': img}},
        {'type': 'text', 'text': 'Describe this UI and list any bugs.'}
    ]}]
)

Fazit

Claude API ist der schnellste Weg zur Produktions-KI. Beginnen Sie mit Nachrichten, fügen Sie Streaming für UX hinzu, nutzen Sie Tools für den Datenzugriff und aktivieren Sie sofortiges Caching, um die Kosten um 90 % zu senken. Claude Sonnet 4 verarbeitet Code, Analyse, Vision und lange Dokumente besser als jedes andere Modell zu seinem Preis im Jahr 2026.

MD Rafikul Islam

Written by

MD Rafikul Islam is a software developer and the editor of TechPulse. He writes about developer tooling, hardware, and the practical decisions that come up in day-to-day engineering work — which laptop to buy, which framework to commit to, why a build broke at 2am. He tests the tools he writes about and says plainly when something is not worth the money. Corrections and corrections requests are welcome at rony.yf25@gmail.com.

✍️ Leave a Comment

Your email address will not be published. Required fields are marked *

🌐 Read in:🇬🇧 English🇩🇪 Deutsch🇧🇷 Português🇸🇦 العربية🇮🇳 हिन्दी🇧🇩 বাংলা