Claude Platform Docs

設定支出限制

$client->beta->organization->spendLimits->set(?string amount, Scope scope, ?SpendLimitPeriod period, ?list<AnthropicBeta> betas): SpendLimit
POST/v1/organizations/spend_limits

設定支出限制。

以(scope, period)為鍵進行 upsert:設定已存在的限制 會就地覆寫。Claude Enterprise 組織設定 user 限制。其席位層級、群組及組織層級的預設值則在 claude.ai 中設定。Claude Console 組織設定 organization 與 workspace 限制,這些限制以每月計算且一律帶有金額。設定這些 限制目前處於搶先體驗預覽階段。如需申請存取權,請聯絡您的 Anthropic 客戶團隊。

Parameters
amount: string

Limit amount as a non-negative integer decimal string in the minor unit of the organization's billing currency (cents for USD): "50000" is $500.00. null sets an explicit no-limit override for this scope and period only — each period resolves independently, so caps for other periods still apply.

scope: Scope

What the limit applies to. Claude Enterprise organizations set user limits. Claude Console organizations set organization and workspace limits. Any other combination returns 400. Setting organization and workspace limits through the API is in an early access preview. To request access, contact your Anthropic account team.

period?: optional SpendLimitPeriod
betas?: optional list<AnthropicBeta>⁠Header parameter

Optional header to specify the beta version(s) you want to use.

Returns
class SpendLimit { $type = 'spend_limit'; $id; $amount; /* 6 more */ }
"spend_limit" type

Object type. Always spend_limit.

string id

Unique tagged ID of the spend limit (spl_...).

?string amount

Limit amount as a non-negative integer decimal string in the minor unit of currency (cents for USD): "50000" is $500.00. null means no numeric cap is configured at this scope — see the effective report for whether a limit applies.

\Datetime createdAt

RFC 3339 datetime at which the spend limit was created.

string currency

ISO 4217 code of the organization's billing currency; the unit for amount.

bool isEnabled

Read-only. false when extra usage is switched off for this organization (organization limit); amount is kept and applies again when it's switched back on. Always true for other limits.

Length of the window the limit resets over. amount caps spend within each period.

Scope scope

What the limit applies to. A tagged union on type; each variant carries the identifier for its scope.

\Datetime updatedAt

RFC 3339 datetime at which the spend limit was last modified.

設定支出限制
<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';

use Anthropic\Client;
use Anthropic\Beta\AnthropicBeta;
use Anthropic\Beta\Organization\SpendLimits\SpendLimitPeriod;

$client = new Client(apiKey: 'my-anthropic-api-key');

$betaSpendLimit = $client->beta->organization->spendLimits->set(
  amount: '50000',
  scope: ['type' => 'user', 'userID' => 'user_01WxYzAbCdEfGhJkMnPqRsTu'],
  period: SpendLimitPeriod::MONTHLY,
  betas: [AnthropicBeta::MESSAGE_BATCHES_2024_09_24],
);

var_dump($betaSpendLimit);
Returns Examples
Response 200
{
  "id": "id",
  "amount": "50000",
  "created_at": "2019-12-27T18:11:19.117Z",
  "currency": "USD",
  "is_enabled": true,
  "period": "daily",
  "scope": {
    "type": "user",
    "user_id": "user_01WxYzAbCdEfGhJkMnPqRsTu"
  },
  "type": "spend_limit",
  "updated_at": "2019-12-27T18:11:19.117Z"
}