# Set a key's credit limit (/docs/api/access/keys_limit_set)

Cap what one key can spend, resetting daily, weekly, monthly or never. null removes the cap. Calls over the cap fail with budget_blocked.

`PUT /v1/keys/{id}/limit`

```json
{
  "operationId": "keys_limit_set",
  "summary": "Set a key's credit limit",
  "description": "Cap what one key can spend, resetting daily, weekly, monthly or never. null removes the cap. Calls over the cap fail with budget_blocked.",
  "tags": [
    "keys"
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "parameters": [
    {
      "schema": {
        "type": "string",
        "pattern": "^[0-9A-Za-z]{12}$"
      },
      "required": true,
      "name": "id",
      "in": "path"
    }
  ],
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "properties": {
            "limit_micro": {
              "type": [
                "integer",
                "null"
              ],
              "minimum": 0,
              "description": "Spend cap for this key in micro-USD; null removes the cap"
            },
            "limit_reset": {
              "type": "string",
              "enum": [
                "day",
                "week",
                "month",
                "never"
              ],
              "default": "never"
            }
          },
          "required": [
            "limit_micro"
          ]
        }
      }
    }
  },
  "responses": {
    "200": {
      "description": "OK",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "limit_micro": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0,
                "description": "Spend cap for this key in micro-USD; null removes the cap"
              },
              "limit_reset": {
                "type": "string",
                "enum": [
                  "day",
                  "week",
                  "month",
                  "never"
                ],
                "default": "never"
              },
              "object": {
                "type": "string",
                "enum": [
                  "key_limit"
                ]
              },
              "key_id": {
                "type": "string"
              },
              "usage_micro": {
                "type": "integer",
                "minimum": 0
              }
            },
            "required": [
              "limit_micro",
              "object",
              "key_id",
              "usage_micro"
            ]
          }
        }
      }
    },
    "default": {
      "description": "Error",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "error": {
                "type": "object",
                "properties": {
                  "code": {
                    "type": "string",
                    "enum": [
                      "invalid_request",
                      "unauthorized",
                      "insufficient_balance",
                      "max_cost_exceeded",
                      "scope_denied",
                      "budget_blocked",
                      "not_found",
                      "idempotency_mismatch",
                      "invalid_meta",
                      "rate_limited",
                      "upstream_error",
                      "response_buffer_limit",
                      "provider_capacity_unavailable",
                      "grid_saturated",
                      "upstream_timeout",
                      "conflict",
                      "internal_error",
                      "account_frozen",
                      "strict_filters",
                      "plan_limit_reached",
                      "validation_failed",
                      "deadline_exceeded",
                      "cancelled"
                    ]
                  },
                  "message": {
                    "type": "string"
                  },
                  "request_id": {
                    "type": "string"
                  },
                  "call_id": {
                    "type": "string"
                  },
                  "retry_after_ms": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "details": {
                    "type": "object",
                    "additionalProperties": {}
                  }
                },
                "required": [
                  "code",
                  "message"
                ]
              }
            },
            "required": [
              "error"
            ]
          }
        }
      }
    }
  }
}
```
