> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aihubmix.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Broadcast

> Broadcast 將 AIHubMix API 請求的 Trace 傳送到外部可觀測性平台，支援設定 LangWatch 目的地、隱私模式、取樣率和 API Key 範圍。

Broadcast 可將 AIHubMix API 請求的 Trace 自動傳送到已設定的外部可觀測性平台。無需在應用程式碼中加入額外埋點，即可在 LangWatch 中監控、除錯和分析 LLM 使用情況。

AIHubMix 目前支援將 LangWatch 設定為 Broadcast 目的地。設定完成後，可以在 LangWatch 中查看模型、token 用量、實際計費成本、耗時、工作階段和 Trace 資訊。

<h2 id="prerequisites">
  準備工作
</h2>

* 一個可用的 [AIHubMix API Key](https://console.aihubmix.com/token)
* 一個 LangWatch 帳號和目標 Project
* AIHubMix 控制台的存取權限

<Warning>
  此整合需要目標 Project 現有的 `Project API Key`，其格式為 `sk-lw-*`。組織或團隊範圍的金鑰，以及 Personal OTLP Endpoint 使用的 `pkey_*`，不適用於此設定。AIHubMix 目前使用 LangWatch 官方雲端位址，不支援自架執行個體。
</Warning>

<h2 id="get-project-api-key">
  1. 取得 LangWatch Project API Key
</h2>

1. 登入 [LangWatch](https://app.langwatch.ai/)，選擇用於接收 AIHubMix Trace 的 Project。
2. 開啟 **Settings → API Keys**。
3. 找到 **Project API Key**。確認其 Scope 是目標 Project，然後選擇複製按鈕。

不需要建立新的 Secret Key。AIHubMix 使用該 Project 內建的 Project API Key。

<Frame>
  <img src="https://mintcdn.com/aihubmix/PiZJ1a0NTd3CcQSY/images/guides/langwatch/langwatch-project-api-key.png?fit=max&auto=format&n=PiZJ1a0NTd3CcQSY&q=85&s=e4f2c0e98769f3359b7c967118b4b2c8" alt="LangWatch Settings 頁面中的 Project API Key" width="1729" height="777" data-path="images/guides/langwatch/langwatch-project-api-key.png" />
</Frame>

<h2 id="add-destination">
  2. 新增 LangWatch 目的地
</h2>

1. 開啟 [AIHubMix 廣播](https://console.aihubmix.com/observability)。
2. 在 **Add destination** 下選擇 **LangWatch**。

<Frame>
  <img src="https://mintcdn.com/aihubmix/FwRluLwfe9pqf0Wh/images/guides/langwatch/aihubmix-observability-overview.png?fit=max&auto=format&n=FwRluLwfe9pqf0Wh&q=85&s=df35c0e79db7f55c71bbc088fb486176" alt="AIHubMix 廣播頁面中的 LangWatch 目的地" width="1729" height="777" data-path="images/guides/langwatch/aihubmix-observability-overview.png" />
</Frame>

3. 填寫設定：

| 設定                              | 說明                                                         |
| ------------------------------- | ---------------------------------------------------------- |
| **Name**                        | 輸入便於識別的名稱，例如 `Production tracing`。                         |
| **API Key**                     | 貼上前一步複製的 LangWatch Project API Key。金鑰會加密儲存，僅用於投遞。          |
| **Privacy**                     | 開啟後不傳送 prompt 和 completion 內容，只傳送 token 用量、實際計費成本、耗時和模型資訊。 |
| **Sampling rate**               | 設定轉送流量的比例。首次驗證建議設為 `100%`。                                 |
| **Only forward these API keys** | 選用。指定需要轉送的 AIHubMix API Key；不選擇時轉送全部 Key 的呼叫記錄。            |

`x-session-id` 請求標頭和請求中的 `user` 欄位會隨記錄傳遞，可用於在 LangWatch 中關聯工作階段或使用者。

<Frame>
  <img src="https://mintcdn.com/aihubmix/PiZJ1a0NTd3CcQSY/images/guides/langwatch/aihubmix-add-destination.png?fit=max&auto=format&n=PiZJ1a0NTd3CcQSY&q=85&s=63f9c79da713529c9acc37e7e851198f" alt="AIHubMix 的 LangWatch 目的地設定表單" width="1729" height="1007" data-path="images/guides/langwatch/aihubmix-add-destination.png" />
</Frame>

<h3 id="test-and-save">
  測試並儲存
</h3>

1. 選擇 **Test**。連線成功後，按鈕會顯示 **Connected**。
2. 選擇 **Add destination** 儲存新目的地。
3. 確認目的地開關已開啟，狀態顯示為 **OK**。

後續修改設定時，選擇 **Save changes** 儲存。

<Frame>
  <img src="https://mintcdn.com/aihubmix/PiZJ1a0NTd3CcQSY/images/guides/langwatch/aihubmix-connection-ok.png?fit=max&auto=format&n=PiZJ1a0NTd3CcQSY&q=85&s=590bea62d4671e867598ac0a2ec81588" alt="AIHubMix 中狀態為 OK 的 LangWatch 目的地" width="1729" height="998" data-path="images/guides/langwatch/aihubmix-connection-ok.png" />
</Frame>

<h2 id="send-test-request">
  3. 傳送驗證請求
</h2>

確認目前 shell 已設定 `AIHUBMIX_API_KEY` 環境變數，然後傳送一次一般模型請求。

```bash cURL theme={null}
curl https://aihubmix.com/v1/chat/completions \
  -H "Authorization: Bearer $AIHUBMIX_API_KEY" \
  -H "Content-Type: application/json" \
  -H "x-session-id: langwatch-tutorial" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [{"role": "user", "content": "What is the meaning of life?"}],
    "user": "langwatch-tutorial"
  }'
```

<Note>記錄採用非同步投遞。請求完成後，Trace 可能需要數秒才會出現在 LangWatch。</Note>

<h2 id="verify-in-langwatch">
  4. 在 LangWatch 中驗證
</h2>

1. 開啟目標 Project 的 **Traces** 頁面。
2. 透過請求使用的模型、`x-session-id` 或 `user` 值尋找記錄。
3. 確認記錄包含耗時、成本、token 和模型資訊。

<Frame>
  <img src="https://mintcdn.com/aihubmix/PiZJ1a0NTd3CcQSY/images/guides/langwatch/langwatch-trace-result.png?fit=max&auto=format&n=PiZJ1a0NTd3CcQSY&q=85&s=f0bf5cb874edaa85ef4c414d40ef710b" alt="LangWatch Traces 頁面中的 AIHubMix API 呼叫" width="1211" height="717" data-path="images/guides/langwatch/langwatch-trace-result.png" />
</Frame>

啟用 Privacy 後，Prompt 等內容欄位會保持空白，但耗時、成本、token 和模型資訊仍會保留。

<Frame>
  <img src="https://mintcdn.com/aihubmix/PiZJ1a0NTd3CcQSY/images/guides/langwatch/langwatch-privacy-columns.png?fit=max&auto=format&n=PiZJ1a0NTd3CcQSY&q=85&s=8459d00d51009145d7e74812cbfb75f2" alt="啟用 Privacy 後 LangWatch 中空白的內容欄位" width="1211" height="717" data-path="images/guides/langwatch/langwatch-privacy-columns.png" />
</Frame>

<h2 id="troubleshooting">
  常見問題
</h2>

<h3 id="test-returns-401">
  Test 回傳 401
</h3>

確認使用的是目標 Project 下的 **Project API Key**。不要使用 Personal OTLP Endpoint 的 `pkey_*`，也不要使用組織或團隊範圍的金鑰。

<h3 id="no-traces">
  儲存成功但沒有 Trace
</h3>

確認目的地已啟用且狀態為 **OK**、Sampling rate 大於 `0%`，以及 API Key 篩選包含請求使用的 Key。等待數秒後重新整理 Traces。

<h3 id="privacy-metrics">
  Privacy 是否影響統計資料
</h3>

Privacy 只停止傳送 prompt 和 completion 內容。token 用量、實際計費成本、耗時和模型資訊仍會傳送。

***

更新時間：2026-08-25
