Anthropic Claude API Claude 4 Opus Sonnet Haiku Integration

We design and deploy artificial intelligence systems: from prototype to production-ready solutions. Our team combines expertise in machine learning, data engineering and MLOps to make AI work not in the lab, but in real business.
Showing 1 of 1 servicesAll 1566 services
Anthropic Claude API Claude 4 Opus Sonnet Haiku Integration
Simple
~1 business day
FAQ
AI Development Areas
AI Solution Development Stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1212
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    852
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_logo-advance_0.png
    B2B Advance company logo design
    561
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822

Anthropic Claude API Integration: Claude 4, Opus, Sonnet, Haiku

Anthropic provides the Claude family with models for different tasks. Claude Opus provides maximum quality for complex tasks. Claude Sonnet balances quality/speed/cost for most production scenarios. Claude Haiku provides fast and inexpensive operations. Claude's distinctive features: large context window (200K tokens), reliable JSON output, Tool Use for agents.

Basic Integration

import anthropic
from pydantic import BaseModel

client = anthropic.Anthropic()  # ANTHROPIC_API_KEY from environment

# Basic call
def chat(prompt: str, model: str = "claude-sonnet-4-5") -> str:
    message = client.messages.create(
        model=model,
        max_tokens=1024,
        messages=[{"role": "user", "content": prompt}]
    )
    return message.content[0].text

# With system prompt
def chat_with_system(system: str, prompt: str) -> str:
    message = client.messages.create(
        model="claude-sonnet-4-5",
        max_tokens=2048,
        system=system,
        messages=[{"role": "user", "content": prompt}],
        temperature=0.1,
    )
    return message.content[0].text

# Streaming
def stream_response(prompt: str):
    with client.messages.stream(
        model="claude-sonnet-4-5",
        max_tokens=1024,
        messages=[{"role": "user", "content": prompt}],
    ) as stream:
        for text in stream.text_stream:
            yield text

# Vision
def analyze_image(image_base64: str, media_type: str, question: str) -> str:
    message = client.messages.create(
        model="claude-sonnet-4-5",
        max_tokens=1024,
        messages=[{
            "role": "user",
            "content": [
                {
                    "type": "image",
                    "source": {
                        "type": "base64",
                        "media_type": media_type,
                        "data": image_base64,
                    },
                },
                {"type": "text", "text": question},
            ],
        }]
    )
    return message.content[0].text

Tool Use (Function Calling)

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

def run_agent_loop(user_message: str) -> str:
    messages = [{"role": "user", "content": user_message}]

    while True:
        response = client.messages.create(
            model="claude-sonnet-4-5",
            max_tokens=1024,
            tools=tools,
            messages=messages,
        )

        if response.stop_reason == "end_turn":
            return response.content[-1].text

        # Process tool_use blocks
        tool_results = []
        for block in response.content:
            if block.type == "tool_use":
                result = dispatch_tool(block.name, block.input)
                tool_results.append({
                    "type": "tool_result",
                    "tool_use_id": block.id,
                    "content": str(result),
                })

        messages.append({"role": "assistant", "content": response.content})
        messages.append({"role": "user", "content": tool_results})

Prompt Caching for Cost Savings

# Cache large static prompts (documents, instructions)
# Cache persists for 5 minutes, saves up to 90% on repeated calls
def cached_analysis(system_doc: str, question: str) -> str:
    message = client.messages.create(
        model="claude-sonnet-4-5",
        max_tokens=1024,
        system=[{
            "type": "text",
            "text": system_doc,
            "cache_control": {"type": "ephemeral"},  # Cache this block
        }],
        messages=[{"role": "user", "content": question}]
    )
    return message.content[0].text

Claude Model Pricing (2025)

Model Input (1M) Output (1M) Context
claude-opus-4 $15 $75 200K
claude-sonnet-4-5 $3 $15 200K
claude-haiku-4-5 $0.80 $4 200K

Timeline

  • Basic integration: 0.5–1 day
  • Tool Use + agent loop: 2–3 days
  • Prompt caching + cost optimization: 1 day