Skip to main content

Description

The Claude series models support official native API calls. Before using, ensure that the anthropic dependency is installed or upgraded:
pip install -U anthropic

Model Information

Model NameClaude Opus 4.6Claude Sonnet 4.6Claude Sonnet 4.5Claude Haiku 4.5
Supports Extended ThinkingYesYesYesYes
Context Window Size200K tokens /
1M tokens (beta)3
200K tokens /
1M tokens (beta)3
200K200K
Maximum Output Length128K tokens128K tokens64K tokens64K tokens
Training Data CutoffAugust 2025August 2025July 2025July 2025

New Features in Claude 4.6

Adaptive Thinking

Claude 4.6 recommends using a new adaptive thinking mode, where Claude automatically determines whether to think and the depth of thinking based on the complexity of the question:
thinking={"type": "adaptive"}
thinking: {type: "enabled", budget_tokens: N} has been deprecated in 4.6 and will be removed in future versions.

Automatic Context Compaction (Beta)

When conversations approach the context window limit, Claude 4.6 can automatically perform server-side summary compaction of earlier content. Advantages:
  • Supports ultra-long conversations
  • No need for client-side summarization
  • Enhances agent’s ability for continuous dialogues
Note:
  • Automatic compaction may lose some details
  • It is recommended to evaluate tests in scenarios requiring strong consistency

Deprecations and Changes

  • Removed interleaved-thinking-2025-05-14 Beta Header: In 4.6, adaptive thinking now automatically supports interleaved thinking, and there is no need to add extra_headers. If still added, this header will be safely ignored.

New Features in Claude 4

New Refusal Stop Reason

The Claude 4 model introduces a new refusal stop reason to handle cases where the model refuses to generate content for safety reasons:
{
  "id": "msg_014XEDjypDjFzgKVWdFUXxZP",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-4-20250514",
  "content": [{"type": "text", "text": "I would be happy to assist you. You can "}],
  "stop_reason": "refusal",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 564,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "output_tokens": 22
  }
}
When migrating to Claude 4, you should update your application to handle the refusal stop reason.

Extended Thinking

Once extended thinking is enabled, the Claude 4 model’s Messages API will return a summary of Claude’s complete thought process. The summary provides all the intelligent advantages of extended thinking while preventing abuse. While the API remains consistent between Claude 3.7 and 4 models, the streaming response for extended thinking may return in a “chunked” mode, with possible delays between streaming events. The summary is processed by a model different from the one specified in your request. The thinking model will not see the summary output.

Interleaved Thinking

Claude 4 model supports interleaving tool usage with extended thinking, allowing for more natural conversations where tool usage and responses can be mixed with regular messages. Interleaved thinking is currently in testing. To enable interleaved thinking, add the test header interleaved-thinking-2025-05-14 in your API request:
extra_headers={
    "anthropic-beta": "interleaved-thinking-2025-05-14"
}
Endpoint: POST /v1/messages

Invocation

curl https://aihubmix.com/v1/messages \
     --header "x-api-key: $ANTHROPIC_API_KEY" \ # Replace with the key generated on AiHubMix
     --header "anthropic-version: 2023-06-01" \
     --header "content-type: application/json" \
     --data \
'{
    "model": "claude-3-5-sonnet-20241022",
    "max_tokens": 1024,
    "messages": [
        {"role": "user", "content": "Hello, world"}
    ]
}'

Body Request Structure

{
  "model": "claude-3-5-sonnet-20241022",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": "What is the meaning of life?"
    }
  ]
}

Request Parameters

NameLocationTypeRequiredDescription
x-api-keyheaderstringNoAIHUBMIX_API_KEY
Content-TypeheaderstringNonone
bodybodyobjectNonone
» modelbodystringYesnone
» messagesbody[object]Yesnone
»» rolebodystringNonone
»» contentbodystringYesnone
» max_tokensbodynumberYesnone

Response Example

200 Response
{
  "id": "msg_013Uf6CwwyjSe35n3yVaPbLM",
  "type": "message",
  "role": "assistant",
  "model": "claude-3-5-sonnet-20241022",
  "content": [
    {
      "type": "text",
      "text": "That's one of humanity's most enduring and complex philosophical questions! While there's no universal answer, I aim to explore such questions thoughtfully while acknowledging their complexity. I try to focus on having meaningful conversations and helping where I can. What does meaning in life mean to you?"
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 14,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "output_tokens": 61
  }
}

Response Results

Status CodeStatus MeaningDescriptionData Model
200OKnoneInline

Migrating to Claude 4

If you are migrating from the Claude 3.7 to Claude 4 models, be aware of the following changes:

Update Model Name

# From Claude 3.7
model="claude-3-7-sonnet-20250219"

# Migrate to Claude 4
model="claude-sonnet-4-20250514"  # or "claude-opus-4-20250514"

Handle New Stop Reasons

Update your application to handle the new refusal stop reason:
if response.stop_reason == "refusal":
    print("Claude refuses to generate this content")
elif response.stop_reason == "end_turn":
    print("Completed normally")

Remove Unsupported Features

  • Token Efficient Tool Usage: Only available in Claude Sonnet 3.7, no longer supported in Claude 4
  • Extended Output: The output-128k-2025-02-19 test header is only available in Claude Sonnet 3.7
If you are migrating from Claude Sonnet 3.7, it is recommended to remove these test headers from your requests:
# Remove these headers (if present)
# "token-efficient-tools-2025-02-19"
# "output-128k-2025-02-19"

Using in Applications (Example with Lobe-Chat)

  • Go to the settings page and select the model provider Claude
  • Input the API key from our site
  • Enter the API proxy address directly as follows:
https://aihubmix.com
  • It is recommended to enable “Use Client Request Mode”
  • Finally, add the models you wish to use to the model list (it is suggested to copy and paste the model name from our website’s settings page)\ Image Image

Claude Text Editing Tools

Claude can use text editing tools defined by Anthropic to view and modify text files, helping you debug, fix, and improve code or other text documents. This enables Claude to interact directly with your files, providing practical operational assistance rather than just suggestions.

Preparation Before Using Text Editing Tools

Select compatible models. Anthropic’s text editing tools support the following Claude models:
  • Claude 4 Series Models (claude-opus-4-20250514, claude-sonnet-4-20250514): text_editor_20250429
  • Claude 3.7 Sonnet (claude-3-7-sonnet-20250219): text_editor_20250124
  • Claude 3.5 Sonnet (claude-3-5-sonnet-20241022): text_editor_20241022
Claude 4 models use a brand new text editing tool that is not compatible with older versions. Please ensure you are using the correct tool type and name.

Tool Configuration per Model

Model VersionTool TypeTool NameSupported Features
Claude 4 (Opus/Sonnet)text_editor_20250429str_replace_based_edit_toolview, str_replace, create
Claude 3.7 Sonnettext_editor_20250124str_replace_editorview, str_replace, create, undo_edit
Claude 3.5 Sonnettext_editor_20241022str_replace_editorview, str_replace, create, undo_edit
Important Change: The Claude 4 model no longer supports the undo_edit command. Please remove any dependencies on this functionality from your code.

Assessment of Use Cases

Here are some typical scenarios for using text editing tools:
  • Code Debugging: Helps identify and fix issues in code, ranging from syntax errors to logical problems.
  • Code Refactoring: Improves code structure, readability, and performance through targeted edits.
  • Documentation Generation: Adds documentation strings, comments, or README files to your codebase.
  • Test Creation: Creates unit tests based on an understanding of the implementation.

Using Text Editing Tools

Provide Claude with text editing tools (named str_replace_editor) through the Messages API: You need to install the anthropic package:
pip install anthropic
Invocation Examples:
import anthropic

client = anthropic.Anthropic(
    api_key="sk-***", # Replace with the key generated on AiHubMix
    base_url="https://aihubmix.com"
)

response = client.messages.create(
    model="claude-sonnet-4-20250514",  # or claude-opus-4-20250514
    max_tokens=1024,
    tools=[
        {
            "type": "text_editor_20250429",
            "name": "str_replace_based_edit_tool"
        }
    ],
    messages=[
        {
            "role": "user", 
            "content": "There's a syntax error in my primes.py file. Can you help me fix it?"
        }
    ]
)

print("Response content:")
for message in response.content:
    print(message.text)

Migrating to Claude 4 (Text Editing Tools)

If you are migrating from Claude 3.7 Sonnet to Claude 4 models, be aware of the following changes:

Update Tool Configuration

python
# Claude 3.7 Sonnet
tools=[
    {
        "type": "text_editor_20250124",
        "name": "str_replace_editor"
    }
]

# Claude 4 (Opus/Sonnet)
tools=[
    {
        "type": "text_editor_20250429",
        "name": "str_replace_based_edit_tool"
    }
]

Remove Unsupported Features

  • undo_edit command: The Claude 4 model no longer supports the undo edit functionality.
  • Please remove any logic that depends on undo_edit from your code.
Response Example:
{
  "id": "msg_bdrk_012xyNaFCQg4zsVcTk5VkDAe",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "I'd be happy to help you fix the syntax error in your `primes.py` file. First, let me take a look at the file to identify the issue."
    },
    {
      "type": "tool_use",
      "text": "",
      "id": "toolu_bdrk_01P6jQG6suDSsDjzugqGVHWC",
      "name": "str_replace_based_edit_tool",
      "input": {
        "command": "view",
        "path": "/repo/primes.py"
      }
    }
  ],
  "model": "claude-sonnet-4-20250514",
  "stop_reason": "tool_use",
  "usage": {
    "input_tokens": 1042,
    "output_tokens": 115
  }
}