> For the complete documentation index, see [llms.txt](https://docs.blockchainsecurity.asia/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.blockchainsecurity.asia/help-center/zheng-he-yu-yi-nan-pai-jie/connecting-your-application.md).

# 串接你的應用程式

把應用程式接上 BCS API 只需幾個步驟。

{% stepper %}
{% step %}

#### 取得 base URL 與 API key

向客戶經理取得正式 base URL，向管理員取得一把 API key。
{% endstep %}

{% step %}

#### 在每個請求帶上 key

於 HTTP header 加入 `X-API-Key: ak_live_…`。建議將 key 存於環境變數或密鑰管理服務。
{% endstep %}

{% step %}

#### 解析統一信封

成功讀 `data`／`meta`，失敗讀 `error.code`。以 `code` 做程式判斷，`message` 僅供顯示。
{% endstep %}

{% step %}

#### 處理計費與限流

讀 `X-Credit-Remaining` 掌握餘額；對 `429` 遵守 `Retry-After`，對 `5xx` 採退避重試。
{% endstep %}

{% step %}

#### 設定即時通知（選用）

需要鏈上事件即時通知時，建立 [Webhook 訂閱](https://api.blockchainsecurity.asia/docs)或使用 WebSocket 串流。
{% endstep %}
{% endstepper %}

## 小提醒

* 自帶 `X-Request-Id` 可串接你自己的追蹤系統；不帶則由系統產生。
* 將不同用途的整合各用一把 key，方便個別控管與撤銷。

遇到問題？見[請求失敗怎麼辦](/help-center/zheng-he-yu-yi-nan-pai-jie/troubleshooting-failed-requests.md)。
