For the complete documentation index, see llms.txt. This page is also available as Markdown.

AI 智能平台

「配置生成式AI API」的相关信息

取得 API 金鑰

請從「AI API 串接」標籤中進入「AI 設定管理」頁面,點選「開通服務」按鈕進入設定頁,並依指示完成確認流程。

要取得 API 金鑰,請點選「查看」。系統可能會要求您輸入帳戶密碼以進行驗證。

設定 AI API

API 網域: https://sgai.littlepig.cloud 端點(Endpoint): /anthropic/v1/messages 通訊協定:HTTPS 請求方式:POST 請求內容格式:Serialized JSON format

請求結構

必要的標頭(Headers)

標頭名稱
類型
說明

x-api-key

字串(string)

從後台管理系統取得的驗證金鑰。

Content-Type

字串(string)

一定要是 application/json.

請求資料定義

參數
類型
是否必填
說明

model

字串(string)

使用的 Claude 模型。

max_tokens

整數(integer)

生成的最大 token 數。

messages

物件陣列(object[])

對話歷史紀錄(請參見「訊息格式」說明)。

stream

布林值(boolean)

以 Server-Sent Events(SSE)方式串流回應。

system

字串(string)

系統級提示詞(system-level prompt)。

temperature

數值(number)

0.0 至 1.0;數值越低越具決定性,數值越高越具創造力。

top_p

數值(number)

Nucleus sampling 比例。請根據需求調整temperature top_p其一。

tools

物件陣列(object[])

模型可能呼叫的外部工具定義。


單一使用情境 — 基本對話功能


訊息格式

純文字格式(簡化版)

明確內容區塊(Explicit Content Blocks)

每則輸入訊息的內容可以是單一字串,或是一組具有特定類型的內容區塊陣列。 若直接使用字串作為內容,則等同於只含有一個類型為 "text" 的內容區塊。 以下兩種輸入訊息格式是等效的:

多輪對話(Multiple Conversational Turns)

部分回應填充(Partially‑filled Response)

圖片 + 文字

支援的圖片格式: image/jpeg, image/png, image/gif, image/webp.


工具定義結構(Tool Definition Schema)

若您在 API 請求中包含工具(tools),模型可能會回傳 tool_use 類型的內容區塊,表示模型正在使用這些工具。 接著,您可以依照模型所產生的工具輸入(tool input)來執行對應的工具,並可選擇性地透過 tool_result 類型的內容區塊,將執行結果回傳給模型。

欄位名稱(Field)
類型
是否必填
說明

name

字串(string)

工具名稱。

description

字串(string)

工具的用途說明。

input_schema

物件(object)

工具輸入的 JSON 結構描述。


回應資料定義(Response Data Definition)

欄位名稱
說明

content

Claude 所產生的內容區塊。

id

訊息 ID。

model

回應內容所使用的模型名稱。

role

角色,一律為 assistant

stop_reason

為何停止生成內容(例如: end_turn)。

usage.input_tokens

請求中所使用的 token 數量。

usage.output_tokens

回應中所產生的 token 數量。

範例


串流事件 (stream=true)

事件
載荷內容

content_block_delta

部分 token 或工具輸入資料。

error

錯誤細節。

範例:

工具呼叫串流:


工具呼叫操作說明


延伸閱讀

https://docs.anthropic.com/en/api/messages

價格

模型價格可能會有所變動,請前往設定管理頁面查看最新價格資訊。

Model
Price / 1 000 input tokens
Price / 1 000 output tokens

claude_3_haiku

$0.00025

$0.00125

claude_3_sonnet

$0.003

$0.015

claude_3_opus

$0.015

$0.075

claude_35_haiku

$0.0008

$0.004

claude_35_sonnet

$0.003

$0.015

claude_37_sonnet

$0.003

$0.015

Last updated

Was this helpful?