跳到正文
API 参考
API 参考

创建 Guardrail

创建可复用的模型、提供方和预算策略。

创建可复用的模型、提供方和预算策略。

端点

POST /api/v1/guardrails
基础 URL
https://runapi.ai
API 版本
v1
身份验证
Authorization: Bearer YOUR_MANAGEMENT_API_KEY
授权
需要账户管理员的 Management API 密钥。
02

请求

JSON 请求体

只能在列出的请求位置发送值。

JSON 请求体10 个字段
allowed_modelsarray | null
可选

Model allowlist.

allowed_providersarray | null
可选

Provider-name allowlist.

blocked_modelsarray | null
可选

Model blocklist, which takes precedence over the allowlist.

blocked_providersarray | null
可选

Provider-name blocklist.

credit_limit_centsinteger | null
可选

Total spending cap in USD cents.

credit_limit_reset_intervalstring | null
可选

Reset cadence for the total spending cap.

可选值: daily, weekly, monthly
descriptionstring
可选

Optional free-form description.

enabledboolean
可选

Whether the guardrail is enforced.

默认值: true
model_budgetsarray | null
可选

Per-model budget rules.

namestring
必填

Guardrail name unique within the account.

03

成功响应

HTTP 201

POST /api/v1/guardrails

JSON
{
  "allowed_models": [
    "gpt-5.4"
  ],
  "allowed_providers": [],
  "assignment_count": 1,
  "blocked_models": [],
  "blocked_providers": [],
  "created_at": "2026-07-27T10:00:00.000Z",
  "credit_limit_cents": 50000,
  "credit_limit_reset_interval": "monthly",
  "description": "Production policy",
  "enabled": true,
  "id": "guardrail_123",
  "model_budgets": [
    {
      "credit_limit_cents": 10000,
      "credit_limit_reset_interval": "monthly",
      "match_mode": "include",
      "models": [
        "gpt-5.4"
      ]
    }
  ],
  "name": "Production budget"
}
04

错误响应 (401)

HTTP 401
响应 Schema
JSON
{
  "properties": {
    "error": {
      "description": "Human-readable error message.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

响应示例

JSON
{
  "error": "Authentication required"
}
05

错误响应 (403)

HTTP 403
响应 Schema
JSON
{
  "properties": {
    "error": {
      "description": "Human-readable error message.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

响应示例

JSON
{
  "error": "Management API key required"
}
06

错误响应 (403)

HTTP 403
响应 Schema
JSON
{
  "properties": {
    "error": {
      "description": "Human-readable error message.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

响应示例

JSON
{
  "error": "Account admin required"
}
07

错误响应 (400)

HTTP 400
响应 Schema
JSON
{
  "oneOf": [
    {
      "properties": {
        "error": {
          "description": "Human-readable error message.",
          "type": "string"
        }
      },
      "required": [
        "error"
      ],
      "type": "object",
      "unevaluatedProperties": false
    },
    {
      "properties": {
        "error": {
          "description": "Human-readable validation summary.",
          "type": "string"
        },
        "errors": {
          "additionalProperties": {
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "description": "Validation messages keyed by public request field, with an array of human-readable strings for each field.",
          "type": "object"
        }
      },
      "required": [
        "error",
        "errors"
      ],
      "type": "object",
      "unevaluatedProperties": false
    }
  ]
}

响应示例

JSON
{
  "error": "page must be an integer"
}
08

错误响应 (422)

HTTP 422
响应 Schema
JSON
{
  "properties": {
    "error": {
      "description": "Human-readable validation summary.",
      "type": "string"
    },
    "errors": {
      "additionalProperties": {
        "items": {
          "type": "string"
        },
        "type": "array"
      },
      "description": "Validation messages keyed by public request field, with an array of human-readable strings for each field.",
      "type": "object"
    }
  },
  "required": [
    "error",
    "errors"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

响应示例

JSON
{
  "error": "Validation failed",
  "errors": {
    "base": [
      "Validation failed"
    ]
  }
}
09

cURL 示例

CURL
curl -X POST https://runapi.ai/api/v1/guardrails \
  -H 'Authorization: Bearer YOUR_MANAGEMENT_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"name":"Production budget","description":"Production policy","enabled":true,"credit_limit_cents":50000,"credit_limit_reset_interval":"monthly","allowed_models":["gpt-5.4"],"model_budgets":[{"match_mode":"include","models":["gpt-5.4"],"credit_limit_cents":10000,"credit_limit_reset_interval":"monthly"}]}'