Zum Hauptinhalt springen

Überblick

LemonData unterstützt den nativen Anthropic Messages API-Pfad, sodass Sie das offizielle Anthropic SDK direkt für Claude-Modelle verwenden können.
Verwenden Sie für das Anthropic SDK https://api.lemondata.cc als Base URL, ohne selbst /v1 anzuhängen.
Typ: Native SDKPrimärer Pfad: Anthropic-nativeSupport-Niveau: Starker nativer Pfad
Among the documented SDK routes, this is one of the strongest-supported LemonData paths for Claude-native features.

Installation

pip install anthropic

Den Client konfigurieren

from anthropic import Anthropic

client = Anthropic(
    api_key="sk-your-lemondata-key",
    base_url="https://api.lemondata.cc",
)

Grundlegende Verwendung

message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Explain LemonData in one sentence."}
    ]
)

print(message.content[0].text)

Streaming

with client.messages.stream(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a short poem about coding."}]
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

Vision

import base64

message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "What's in this image?"},
            {
                "type": "image",
                "source": {
                    "type": "url",
                    "url": "https://example.com/image.jpg"
                }
            }
        ]
    }]
)

with open("image.png", "rb") as f:
    image_data = base64.b64encode(f.read()).decode()

message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "Describe this image"},
            {
                "type": "image",
                "source": {
                    "type": "base64",
                    "media_type": "image/png",
                    "data": image_data
                }
            }
        ]
    }]
)

Tool-Nutzung

message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    tools=[{
        "name": "get_weather",
        "description": "Get the weather for a location",
        "input_schema": {
            "type": "object",
            "properties": {
                "location": {"type": "string"}
            },
            "required": ["location"]
        }
    }],
    messages=[{"role": "user", "content": "What's the weather in Tokyo?"}]
)

for block in message.content:
    if block.type == "tool_use":
        print(block.name)
        print(block.input)

Erweitertes Denken

message = client.messages.create(
    model="claude-opus-4-6",
    max_tokens=16000,
    thinking={
        "type": "enabled",
        "budget_tokens": 10000
    },
    messages=[{"role": "user", "content": "Solve this complex problem step by step."}]
)

for block in message.content:
    if block.type == "thinking":
        print(block.thinking)
    elif block.type == "text":
        print(block.text)

Empfohlene Claude-Modelle

ModelBest For
claude-opus-4-6Tiefes Schlussfolgern, ausführliche Analysen
claude-sonnet-4-6Coding, allgemeine Assistant-Aufgaben
claude-haiku-4-5Schnelle, leichtgewichtige Antworten

Fehlerbehebung

  • Verwenden Sie https://api.lemondata.cc
  • Hängen Sie /v1 nicht manuell an, wenn Sie das Anthropic SDK konfigurieren
  • Prüfen Sie, ob Ihr LemonData API-Schlüssel mit sk- beginnt
  • Bestätigen Sie, dass der Schlüssel im LemonData-Dashboard aktiv ist
  • Lassen Sie das Anthropic SDK den Auth-Header verwalten, anstatt manuell benutzerdefinierte Header hinzuzufügen
  • Verifizieren Sie den Claude-Modellnamen exakt
  • Prüfen Sie die aktuelle Verfügbarkeit im LemonData-Modellkatalog