๐ŸŒ Detecting your locationโ€ฆ
๐Ÿ“ข Advertisement โ€” Configure AdSense in Appearance โ†’ Customize โ†’ AdSense Settings

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.

โœ๏ธ Leave a Comment

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

๐ŸŒ Read in:๐Ÿ‡ฌ๐Ÿ‡ง English๐Ÿ‡ฉ๐Ÿ‡ช Deutsch๐Ÿ‡ง๐Ÿ‡ท Portuguรชs๐Ÿ‡ธ๐Ÿ‡ฆ ุงู„ุนุฑุจูŠุฉ๐Ÿ‡ฎ๐Ÿ‡ณ เคนเคฟเคจเฅเคฆเฅ€๐Ÿ‡ง๐Ÿ‡ฉ เฆฌเฆพเฆ‚เฆฒเฆพ