AIHubmix Claude 原生接口 Claude Opus 4.7 调用示例 (返回思考摘要)
from openai import OpenAIclient = OpenAI( base_url="https://aihubmix.com/v1", api_key="<AIHUBMIX_API_KEY>",)completion = client.chat.completions.create( model="claude-opus-4-7", messages=[ { "role": "user", "content": "A snail is at the bottom of a 10-meter well. Each day it climbs 3 meters, but each night it slides back 2 meters. How many days does it take to reach the top?" } ], extra_body={ "reasoning": {"effort": "xhigh", "display": "summarized"} })print(completion.choices[0].message.content)
启用扩展思考后,Claude 4 模型的 Messages API 会返回 Claude 完整思考过程的摘要。摘要思考提供了扩展思考的全部智能优势,同时防止滥用。虽然 API 在 Claude 3.7 和 4 模型之间保持一致,但扩展思考的流式响应可能以”块状”传递模式返回,流式事件之间可能存在延迟。摘要由与您在请求中指定的模型不同的模型处理。思考模型不会看到摘要输出。
{ "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 }}
{ "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 }}