> For the complete documentation index, see [llms.txt](https://docs.apismart.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apismart.ai/documentation/zh-tw/sdk-yu-qian-yi/curl.md).

# cURL

使用 cURL 可直接從終端機或命令列傳送 ApiSmart API 請求。

這對於測試驗證、驗證 Model ID，以及在將 API 整合到應用程式之前檢查請求格式很有幫助。

關於一般 API 規則，請參閱 [**API 基礎**](/documentation/zh-tw/api-zhi-nan/api-ji-chu.md).

***

### 開始之前

請確認你具備：

* 一個已啟用的 **API 權杖**
* 充足的 **目前餘額**
* 一個有效的 **模型 ID**
* 系統上已安裝 cURL

將您的 API Token 設為環境變數：

```bash
export APISMART_API_KEY="YOUR_API_KEY"
```

***

### 聊天完成

向支援的語言模型送出請求：

```bash
curl https://gw.apismart.ai/v1/chat/completions \\
  -H "Authorization: Bearer $APISMART_API_KEY" \\
  -H "Content-Type: application/json" \\
  -d '{
    "model": "YOUR_MODEL_ID",
    "messages": [
      {
        "role": "user",
        "content": "哈囉！"
      }
    ]
  }'
```

替換 `YOUR_MODEL_ID` 為所選模型詳情頁上顯示的確切模型 ID **程式碼範例**.

***

### 圖片生成

送出基本的圖片生成請求：

```bash
curl https://gw.apismart.ai/v1/images/generations \
  -H "Authorization: Bearer $APISMART_API_KEY" \\
  -H "Content-Type: application/json" \\
  -d '{
    "model": "YOUR_MODEL_ID",
    "prompt": "夕陽下的未來城市"
  }'
```

圖片請求欄位可能因模型而異。

***

### 影片生成

影片生成使用非同步任務工作流程。

對於接受 `prompt` 與 `duration`的模型，請求可能如下：

```bash
curl https://gw.apismart.ai/v1/video/tasks \
  -H "Authorization: Bearer $APISMART_API_KEY" \\
  -H "Content-Type: application/json" \\
  -d '{
    "model": "YOUR_MODEL_ID",
    "prompt": "夕陽下的電影感海浪景象",
    "duration": 5
  }'
```

接著使用回傳的任務 ID 來檢查其狀態：

```bash
curl https://gw.apismart.ai/v1/video/tasks/{task_id} \
  -H "Authorization: Bearer $APISMART_API_KEY"
```

> ⚠️ **重要：** 請務必使用所選模型中顯示的確切 Model ID、端點、請求欄位與支援的值 **程式碼範例**.

***

### 常用選項

有用的 cURL 選項包括：

| 選項   | 目的           |
| ---- | ------------ |
| `-H` | 新增請求標頭       |
| `-d` | 傳送請求本文       |
| `-i` | 包含回應標頭       |
| `-v` | 顯示詳細的請求與連線資訊 |

使用 `-v` 在排查連線或 HTTP 請求問題時，但請避免分享包含完整 API Token 的輸出內容。

***

### 🛠️ 常見問題

| 問題           | 檢查項目                  |
| ------------ | --------------------- |
| **401／驗證錯誤** | API Token 與 Bearer 標頭 |
| **找不到模型**    | 精確的模型 ID 與大小寫         |
| **無效的請求**    | 端點、JSON 語法與模型專屬欄位     |
| **餘額不足**     | 目前餘額與 API 權杖剩餘額度      |

對於失敗的請求，請查看相關記錄於 [**使用紀錄與成本**](/documentation/zh-tw/api-shi-yong/shi-yong-ji-lu-yu-fei-yong.md).

> 🔐 絕不要向支援提供你的完整 API Token。

***

### 🚀 下一步

繼續進行：

* [Python](/documentation/zh-tw/sdk-yu-qian-yi/python.md)
* [JavaScript 和 TypeScript](/documentation/zh-tw/sdk-yu-qian-yi/javascript-yu-typescript.md)
* [API 基礎](/documentation/zh-tw/api-zhi-nan/api-ji-chu.md)
* [選擇模型並尋找其模型 ID](/documentation/zh-tw/mo-xing-yu-ding-jia/mo-xing-yu-mo-xing-id.md)
* [Chat Completions API](/documentation/zh-tw/api-zhi-nan/liao-tian-wan-cheng-api.md)
