---
title: 建立 API 金鑰 | RunAPI
description: 建立標準 API 金鑰。請儲存此操作返回的明文金鑰，因為它只顯示一次。
url: https://runapi.ai/zh-HK/docs/api/management/keys/create.md
canonical: https://runapi.ai/zh-HK/docs/api/management/keys/create
locale: zh-HK
---

> HTML 版本: https://runapi.ai/zh-HK/docs/api/management/keys/create
> 智能代理網站索引: https://runapi.ai/llms.txt

# 建立 API 金鑰

建立標準 API 金鑰。請儲存此操作返回的明文金鑰，因為它只顯示一次。

## 端點

POST /api/v1/keys

基礎 URL: https://runapi.ai

API 版本: v1

身份驗證: Authorization: Bearer YOUR_MANAGEMENT_API_KEY


授權: 需要帳號管理員管理 API 金鑰。新的標準 API 金鑰由呼叫者擁有。

## 請求

僅在列出的請求位置傳送值。

### JSON 內文

```json
{
  "allowed_models": {
    "description": "模型識別符的可選白名單。",
    "required": false,
    "type": "array | null"
  },
  "credit_limit_cents": {
    "description": "以美分為單位的可選消費上限。",
    "required": false,
    "type": "integer | null"
  },
  "credit_limit_reset_interval": {
    "description": "金鑰消費上限的可選重置週期。",
    "enum": [
      "daily",
      "weekly",
      "monthly"
    ],
    "required": false,
    "type": "string | null"
  },
  "credit_limit_windows": {
    "description": "以 1h、1d 或 7d 為鍵的滾動消費上限；每個值包含一個正整數 limit_cents。",
    "required": false,
    "type": "object"
  },
  "enabled": {
    "default": true,
    "description": "使用此金鑰的請求是否被接受。",
    "required": false,
    "type": "boolean"
  },
  "guardrail_id": {
    "description": "建立時附加的可選護欄前綴 ID。",
    "required": false,
    "type": "string"
  },
  "name": {
    "description": "API 金鑰的友好名稱。",
    "required": false,
    "type": "string"
  }
}
```

## 成功回應

HTTP 201 - POST /api/v1/keys

```json
{
  "allowed_models": [
    "gpt-5.4"
  ],
  "created_at": "2026-07-27T10:00:00.000Z",
  "credit_limit_cents": 1000,
  "credit_limit_reset_interval": "daily",
  "credit_limit_windows": {
    "1d": {
      "limit_cents": 500
    },
    "1h": {
      "limit_cents": 100
    },
    "7d": {
      "limit_cents": 2000
    }
  },
  "enabled": true,
  "guardrail_id": "guardrail_123",
  "id": "token_123",
  "key": "runapi_plaintext_example",
  "last_used_at": null,
  "masked_token": "runapi_abc...wxyz",
  "name": "Production"
}
```

## 錯誤回應（401）

HTTP 401

### 回應結構

```json
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}
```

### 回應範例

```json
{
  "error": "Authentication required"
}
```

## 錯誤回應（403）

HTTP 403

### 回應結構

```json
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}
```

### 回應範例

```json
{
  "error": "Management API key required"
}
```

## 錯誤回應（403）

HTTP 403

### 回應結構

```json
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}
```

### 回應範例

```json
{
  "error": "Account admin required"
}
```

## 錯誤回應（400）

HTTP 400

### 回應結構

```json
{
  "oneOf": [
    {
      "properties": {
        "error": {
          "description": "人類可讀的錯誤訊息。",
          "type": "string"
        }
      },
      "required": [
        "error"
      ],
      "type": "object",
      "unevaluatedProperties": false
    },
    {
      "properties": {
        "error": {
          "description": "人類可讀的驗證摘要。",
          "type": "string"
        },
        "errors": {
          "additionalProperties": {
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "description": "以公開請求欄位為鍵的驗證訊息，每個欄位對應一組人類可讀的字串陣列。",
          "type": "object"
        }
      },
      "required": [
        "error",
        "errors"
      ],
      "type": "object",
      "unevaluatedProperties": false
    }
  ]
}
```

### 回應範例

```json
{
  "error": "page must be an integer"
}
```

## 錯誤回應（422）

HTTP 422

### 回應結構

```json
{
  "properties": {
    "error": {
      "description": "人類可讀的驗證摘要。",
      "type": "string"
    },
    "errors": {
      "additionalProperties": {
        "items": {
          "type": "string"
        },
        "type": "array"
      },
      "description": "以公開請求欄位為鍵的驗證訊息，每個欄位對應一組人類可讀的字串陣列。",
      "type": "object"
    }
  },
  "required": [
    "error",
    "errors"
  ],
  "type": "object",
  "unevaluatedProperties": false
}
```

### 回應範例

```json
{
  "error": "Validation failed",
  "errors": {
    "base": [
      "Validation failed"
    ]
  }
}
```

## cURL 範例



### curl

```curl
curl -X POST https://runapi.ai/api/v1/keys \
  -H 'Authorization: Bearer YOUR_MANAGEMENT_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"name":"Production","credit_limit_cents":1000,"credit_limit_reset_interval":"daily","credit_limit_windows":{"1h":{"limit_cents":100},"1d":{"limit_cents":500},"7d":{"limit_cents":2000}},"allowed_models":["gpt-5.4"],"guardrail_id":"guardrail_123"}'
```

## 相關參考資料

- [API 金鑰](https://runapi.ai/zh-HK/docs/api/management/keys.md)
- [API 金鑰物件](https://runapi.ai/zh-HK/docs/api/management/keys/object.md)

---

## RunAPI 的更多內容

- [首頁](https://runapi.ai/zh-HK/.md)
- [模型目錄](https://runapi.ai/zh-HK/models.md)
- [收費](https://runapi.ai/zh-HK/pricing.md)
- [服務商](https://runapi.ai/zh-HK/models)
- [文件](https://runapi.ai/zh-HK/docs/guides)
- [SDK](https://runapi.ai/zh-HK/sdk.md)
- [CLI](https://runapi.ai/zh-HK/cli.md)
- [MCP Server](https://runapi.ai/zh-HK/mcp.md)
- [Claude Code 與 Cursor](https://runapi.ai/zh-HK/claude-code-vs-cursor.md)
- [Cursor API 設定](https://runapi.ai/zh-HK/cursor-api-setup.md)
- [RunAPI 與 OpenRouter](https://runapi.ai/zh-HK/openrouter-alternative.md)
- [企業版](https://runapi.ai/zh-HK/contact.md)
- [聯絡](https://runapi.ai/zh-HK/contact.md)
- [條款](https://runapi.ai/zh-HK/terms.md)
- [私隱](https://runapi.ai/zh-HK/privacy.md)
- [智能代理網站索引](https://runapi.ai/llms.txt)

聯絡我們: contact@runapi.ai

## 結構化資料

```json
[
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-HK",
    "@type": "WebSite",
    "name": "RunAPI",
    "url": "https://runapi.ai/zh-HK",
    "potentialAction": {
      "@type": "SearchAction",
      "target": {
        "@type": "EntryPoint",
        "urlTemplate": "https://runapi.ai/zh-HK/models?q={search_term_string}"
      },
      "query-input": "required name=search_term_string"
    }
  },
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-HK",
    "@type": "Organization",
    "name": "RunAPI",
    "url": "https://runapi.ai/zh-HK",
    "logo": {
      "@type": "ImageObject",
      "url": "https://runapi.ai/zh-HKicon.svg"
    },
    "sameAs": [
      "https://github.com/runapi-ai"
    ]
  },
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-HK",
    "@type": "TechArticle",
    "headline": "建立 API 金鑰",
    "description": "建立標準 API 金鑰。請儲存此操作返回的明文金鑰，因為它只顯示一次。",
    "url": "https://runapi.ai/zh-HK/docs/api/management/keys/create",
    "mainEntityOfPage": "https://runapi.ai/zh-HK/docs/api/management/keys/create"
  }
]
```
