如何獲取及配置訪問Claude 3.7 Sonnet API?

如何獲取及配置訪問Claude 3.7 Sonnet API?

Claude 3.7 Sonnet 由 Anthropic 開發,是一個強大的人工智慧模型,以其先進的推理和編碼能力而聞名。訪問其 API 開啟了將這一尖端技術整合到您的應用程式中的大門,從自動執行復雜任務到生成富有洞察力的響應。在本指南中,我將向您介紹獲取及配置訪問 Claude 3.7 Sonnet API 的步驟。

Claude 3.7 Sonnet有哪些新功能?

Claude 3.7 Sonnet 不僅在效能方面,而且在準確性和邏輯性方面都超越了其前代產品。其中最大的亮點如下

1. 混合推理架構

與早期型號不同,Claude 3.7 引入了雙模處理技術

  • 即時響應:用於摘要、事實核查和問答等查詢。
  • 擴充套件推理:用於程式碼生成、基於邏輯的決策和多步驟問題解決等更復雜的活動。

這種用例優化融合了不同的用例,在平衡來電和真正的深度推理時也只是優化了速度。

2. API增強與開發人員靈活性

Claude 3.7 允許開發人員在 API 下通過推理的速度或深度來控制處理時間,從而使其具有成本效益,以滿足所有應用程式或專案的要求。開發人員現在可以

  • 設定 API 呼叫的處理時間界限。
  • 針對不同應用改變模型行為。
  • 根據任務的複雜程度,對克勞德進行深度推理。

3. 效能和準確性提升

  • 響應速度比 Claude 3 快 20%-30%
  • 現在,涉及編碼、數學和分析的基於邏輯的工作執行效率提高了 15%。
  • 為大容量 API 使用者降低 40% 的成本
  • 由於 提高了上下文感知能力,響應效果更好

4. 增強的視覺功能

現在,Claude 3.7 Sonnet 能夠檢視影象,提取它所理解的資訊,並對視覺傳達的內容進行推理。

5. 讓思維更準確、更透明

Claude 3.7 Sonnet 在回答複雜問題時,通過更好的可視性一步步闡明推理,這一點也得到了改進。

如何使用Claude 3.7 Sonnet API介面?

將 Claude 3.7 整合到您的應用程式中非常簡單。請按照以下步驟開始使用:

Step 1: 獲取API訪問許可權

  1. Anthropic的開發人員入口網站 註冊 API 訪問許可權。。
  2. 在您的賬戶控制面板中生成一個 API 金鑰

Step 2: 安裝所需的庫

如果您使用 Python,請安裝必要的庫:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
pip install anthropic
pip install anthropic
pip install anthropic

Step 3: 呼叫API介面

查詢 Claude 的基本示例:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-3-7-sonnet-20250219",
max_tokens=1000, temperature=1,
system="You are a world-class poet. Respond only with short poems.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "Why is the ocean salty?"
}
]
}
]
)
print(message.content)
import anthropic client = anthropic.Anthropic() message = client.messages.create( model="claude-3-7-sonnet-20250219", max_tokens=1000, temperature=1, system="You are a world-class poet. Respond only with short poems.", messages=[ { "role": "user", "content": [ { "type": "text", "text": "Why is the ocean salty?" } ] } ] ) print(message.content)
import anthropic
client = anthropic.Anthropic() 
message = client.messages.create( 
model="claude-3-7-sonnet-20250219", 
max_tokens=1000, temperature=1, 
system="You are a world-class poet. Respond only with short poems.", 
messages=[ 
{ 
"role": "user", 
"content": [ 
{ 
"type": "text", 
"text": "Why is the ocean salty?" 
} 
] 
} 
   ] 
) 
print(message.content)

此 API 呼叫實時傳送查詢並檢索 Claude 的響應。

Step 4: 根據用例進行微調

開發人員可以通過以下方式優化 API 呼叫

  • 為創造性調整 temperature settings(溫度設定)
  • 為複雜查詢啟用 extended reasoning(擴充套件推理)
  • 使用 structured prompts(結構化提示)以提高準確性。

測試Claude 3.7 Sonnet API功能

現在,讓我們用實際場景來測試 Claude:

測試 1:影象分析 – 印度 vs 巴基斯坦板球比賽

以印度 vs 巴基斯坦冠軍盃比賽為例,克勞德將看到一張圖片,並被要求提供重要細節。

  • 識別球員、球場和賽事細節。
  • 總結比賽場景(例如,“印度隊在最後一局中落後 5 個小門”)。
  • 從記分牌中提取文字。

輸入影象:

印度 vs 巴基斯坦板球比賽

輸入程式碼: 

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-3-7-sonnet-20250219",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": image1_media_type,
"data": image1_data,
},
},
{
"type": "text",
"text": "You are analyzing an image from the India vs Pakistan Champions Trophy 2025 match. "
"Extract and summarize the most relevant insights in the following structured order:\n\n"
"1️⃣ **Match Overview**: Identify the teams, tournament, stadium, and year.\n"
"2️⃣ **Key Players**: Recognize any visible players based on jerseys, number, and positioning.\n"
"3️⃣ **Match Context**: Determine which team is batting, the current score, overs, and any visible scoreboard data.\n"
"4️⃣ **Text Extraction**: If a scoreboard or banners are visible, extract relevant text (e.g., scores, team names, advertisements).\n"
"5️⃣ **Atmosphere & Crowd**: Describe the overall scene (e.g., crowd intensity, celebrations, flags, banners).\n"
"6️⃣ **Highlight Events**: Identify any key moments such as a boundary, wicket, appeal, or fielder's action.\n\n"
"⚠️ **Ensure factual accuracy by only describing visible elements. Avoid assumptions.**"
}
],
}
],
)
display(Markdown(message.content[0].text))
import anthropic client = anthropic.Anthropic() message = client.messages.create( model="claude-3-7-sonnet-20250219", max_tokens=1024, messages=[ { "role": "user", "content": [ { "type": "image", "source": { "type": "base64", "media_type": image1_media_type, "data": image1_data, }, }, { "type": "text", "text": "You are analyzing an image from the India vs Pakistan Champions Trophy 2025 match. " "Extract and summarize the most relevant insights in the following structured order:\n\n" "1️⃣ **Match Overview**: Identify the teams, tournament, stadium, and year.\n" "2️⃣ **Key Players**: Recognize any visible players based on jerseys, number, and positioning.\n" "3️⃣ **Match Context**: Determine which team is batting, the current score, overs, and any visible scoreboard data.\n" "4️⃣ **Text Extraction**: If a scoreboard or banners are visible, extract relevant text (e.g., scores, team names, advertisements).\n" "5️⃣ **Atmosphere & Crowd**: Describe the overall scene (e.g., crowd intensity, celebrations, flags, banners).\n" "6️⃣ **Highlight Events**: Identify any key moments such as a boundary, wicket, appeal, or fielder's action.\n\n" "⚠️ **Ensure factual accuracy by only describing visible elements. Avoid assumptions.**" } ], } ], ) display(Markdown(message.content[0].text))
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
   model="claude-3-7-sonnet-20250219",
   max_tokens=1024,
   messages=[
       {
           "role": "user",
           "content": [
               {
                   "type": "image",
                   "source": {
                       "type": "base64",
                       "media_type": image1_media_type,
                       "data": image1_data,
                   },
               },
               {
                   "type": "text",
                   "text": "You are analyzing an image from the India vs Pakistan Champions Trophy 2025 match. "
                       "Extract and summarize the most relevant insights in the following structured order:\n\n"
                       "1️⃣ **Match Overview**: Identify the teams, tournament, stadium, and year.\n"
                       "2️⃣ **Key Players**: Recognize any visible players based on jerseys, number, and positioning.\n"
                       "3️⃣ **Match Context**: Determine which team is batting, the current score, overs, and any visible scoreboard data.\n"
                       "4️⃣ **Text Extraction**: If a scoreboard or banners are visible, extract relevant text (e.g., scores, team names, advertisements).\n"
                       "5️⃣ **Atmosphere & Crowd**: Describe the overall scene (e.g., crowd intensity, celebrations, flags, banners).\n"
                       "6️⃣ **Highlight Events**: Identify any key moments such as a boundary, wicket, appeal, or fielder's action.\n\n"
                       "⚠️ **Ensure factual accuracy by only describing visible elements. Avoid assumptions.**"
               }
           ],
       }
   ],
)
display(Markdown(message.content[0].text))

輸出:

比賽視訊截圖分析輸出

測試 2:通過邏輯推理解決問題

我們為 Claude 設定了一個多階段問題的挑戰:

“一列火車以每小時 80 英里的速度從紐約開往芝加哥。另一列火車以每小時 70 英里的速度從芝加哥開往紐約。它們相距 800 英里。它們何時相遇?

Claude 將使用逐步邏輯推理的方法分解問題 .

輸入程式碼:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
output = anthropic.Anthropic().messages.create(
model="claude-3-7-sonnet-20250219",
max_tokens=1024,
messages=[
{"role": "user",
"content": """
A train leaves New York heading toward Chicago at 80 mph.
Another train leaves Chicago for New York at 70 mph.
They are 800 miles apart. When do they meet?
"""
}
]
)
display(Markdown(output.content[0].text))
output = anthropic.Anthropic().messages.create( model="claude-3-7-sonnet-20250219", max_tokens=1024, messages=[ {"role": "user", "content": """ A train leaves New York heading toward Chicago at 80 mph. Another train leaves Chicago for New York at 70 mph. They are 800 miles apart. When do they meet? """ } ] ) display(Markdown(output.content[0].text))
output = anthropic.Anthropic().messages.create(
   model="claude-3-7-sonnet-20250219",
   max_tokens=1024,
   messages=[
       {"role": "user",
        "content": """
               A train leaves New York heading toward Chicago at 80 mph.
               Another train leaves Chicago for New York at 70 mph.
               They are 800 miles apart. When do they meet?
               """
               }
   ]
)
display(Markdown(output.content[0].text))

輸出:

邏輯推理解決火車相遇問題

測試 3:HTML動畫 – 彈球模擬

接下來,我們將請 Claude 製作一些 HTML 動畫

“編寫一個 HTML CSS+JavaScript 程式,模擬一個球在一系列巢狀圓圈內彈跳;每個圓圈都有一個開口。每當小球觸碰到一個極限時,內部就會開啟,然後小球就會跟隨重力和動量運動”。

這項測試將展示 Claude 的以下能力:

  • 生成功能性、互動式網頁程式碼
  • 模擬物理動畫
  • 確保 HTML/CSS/JS 中的邏輯和語法正確無誤

輸入程式碼:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
output = anthropic.Anthropic().messages.create(
model="claude-3-7-sonnet-20250219",
max_tokens=1024,
messages=[
{"role": "user",
"content": """
Write an HTML CSS+JavaScript program, simulating a ball that
bounces inside a circle;
the ball follows gravity and momentum.
"""
}
]
)
display(Markdown(output.content[0].text))
output = anthropic.Anthropic().messages.create( model="claude-3-7-sonnet-20250219", max_tokens=1024, messages=[ {"role": "user", "content": """ Write an HTML CSS+JavaScript program, simulating a ball that bounces inside a circle; the ball follows gravity and momentum. """ } ] ) display(Markdown(output.content[0].text))
output = anthropic.Anthropic().messages.create(
   model="claude-3-7-sonnet-20250219",
   max_tokens=1024,
   messages=[
       {"role": "user",
        "content": """
               Write an HTML CSS+JavaScript program, simulating a ball that
               bounces inside a circle;
               the ball follows gravity and momentum.
               """
               }
   ]
)
display(Markdown(output.content[0].text))

輸出影象:

Claude API解決HTML程式碼問題

輸出:

小結

Claude 3.7 Sonnet 不僅僅是另一種人工智慧模型,它在推理能力、準確性和適應性方面都取得了重大進步。它能夠在即時響應和擴充套件思考之間無縫切換,這使它成為開發人員的首選。以下是文章的主要觀點:

  • 具有混合推理功能的更智慧 API,兼顧速度與深度。
  • 通過板球比賽分析證明了影象理解能力。
  • 通過基於邏輯的查詢展示解決問題的效率。
  • 通過互動式物理模擬展示 HTML 程式碼生成。

隨著人工智慧的飛速發展,Claude 3.7 Sonnet 作為一款可靠、透明和多功能的工具脫穎而出。無論您是工程師、研究人員還是企業領導,它都能為您在工作中利用先進的人工智慧提供完美的解決方案。

評論留言