# Update spending limits Update organization, total API key, and/or individual API key spending limits. Supports updating any combination of limits in a single request. ## Limit Hierarchy The system enforces a three-tier limit hierarchy: 1. **Organization Limit** (`monthly_api_limit`) - Total spending across all usage types 2. **Total API Key Limit** (`total_api_key_limit`) - Combined spending of all API keys 3. **Individual API Key Limit** (`api_key_limit`) - Spending for a specific API key **Validation Rule:** `total_api_key_limit` must not exceed `monthly_api_limit`. ## Update Options This endpoint supports multiple update scenarios: 1. **Update Organization Limit Only** - Provide `monthly_api_limit` 2. **Update Total API Key Limit Only** - Provide `total_api_key_limit` 3. **Update Individual API Key Limit Only** - Provide `api_key_id` + `api_key_limit` 4. **Update Multiple Limits** - Provide any combination of the above fields #### Path Parameters **`org_id`** string required The organization ID (format: `org_`). #### Request Body At least one field must be provided. All limits are in CHF and must be positive numbers (> 0). **`monthly_api_limit`** number optional Organization monthly limit in CHF. Must be > 0. This is the total spending cap across all usage types. **`total_api_key_limit`** number optional Total API key monthly limit in CHF. Must be > 0 and cannot exceed `monthly_api_limit`. This is the combined spending cap for all API keys. **`api_key_id`** string optional API key ID (format: `apikey_`). Required when updating an individual API key limit. **`api_key_limit`** number optional Individual API key monthly limit in CHF. Must be > 0. Requires `api_key_id` to be provided. ## Returns Returns a success message and the updated limit values when limits are updated successfully. Updates are atomic - all changes succeed or all fail. Update Organization Limit ```bash curl -X PUT "https://api.aitronos.com/v1/analytics/usage/limits/org_abc123" \ -H "X-API-Key: $FREDDY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "monthly_api_limit": 2000.00 }' ``` ```python import os import requests api_key = os.environ["FREDDY_API_KEY"] org_id = "org_abc123" response = requests.put( f"https://api.aitronos.com/v1/analytics/usage/limits/{org_id}", headers={"X-API-Key": api_key}, json={"monthly_api_limit": 2000.00} ) data = response.json() print(data["message"]) ``` ```javascript const response = await fetch( "https://api.aitronos.com/v1/analytics/usage/limits/org_abc123", { method: "PUT", headers: { "X-API-Key": process.env.FREDDY_API_KEY, "Content-Type": "application/json" }, body: JSON.stringify({ monthly_api_limit: 2000.00 }) } ); const data = await response.json(); console.log(data.message); ``` Update API Key Limit ```bash curl -X PUT "https://api.aitronos.com/v1/analytics/usage/limits/org_abc123" \ -H "X-API-Key: $FREDDY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "api_key_id": "apikey_def456", "api_key_limit": 1000.00 }' ``` ```python import os import requests api_key = os.environ["FREDDY_API_KEY"] org_id = "org_abc123" response = requests.put( f"https://api.aitronos.com/v1/analytics/usage/limits/{org_id}", headers={"X-API-Key": api_key}, json={ "api_key_id": "apikey_def456", "api_key_limit": 1000.00 } ) data = response.json() print(data["message"]) ``` ```javascript const response = await fetch( "https://api.aitronos.com/v1/analytics/usage/limits/org_abc123", { method: "PUT", headers: { "X-API-Key": process.env.FREDDY_API_KEY, "Content-Type": "application/json" }, body: JSON.stringify({ api_key_id: "apikey_def456", api_key_limit: 1000.00 }) } ); const data = await response.json(); console.log(data.message); ``` Update Total API Key Limit ```bash curl -X PUT "https://api.aitronos.com/v1/analytics/usage/limits/org_abc123" \ -H "X-API-Key: $FREDDY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "total_api_key_limit": 7000.00 }' ``` ```python import os import requests api_key = os.environ["FREDDY_API_KEY"] org_id = "org_abc123" response = requests.put( f"https://api.aitronos.com/v1/analytics/usage/limits/{org_id}", headers={"X-API-Key": api_key}, json={"total_api_key_limit": 7000.00} ) data = response.json() print(data["message"]) ``` ```javascript const response = await fetch( "https://api.aitronos.com/v1/analytics/usage/limits/org_abc123", { method: "PUT", headers: { "X-API-Key": process.env.FREDDY_API_KEY, "Content-Type": "application/json" }, body: JSON.stringify({ total_api_key_limit: 7000.00 }) } ); const data = await response.json(); console.log(data.message); ``` Update All Limits ```bash curl -X PUT "https://api.aitronos.com/v1/analytics/usage/limits/org_abc123" \ -H "X-API-Key: $FREDDY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "monthly_api_limit": 10000.00, "total_api_key_limit": 7000.00, "api_key_id": "apikey_def456", "api_key_limit": 5000.00 }' ``` ```python import os import requests api_key = os.environ["FREDDY_API_KEY"] org_id = "org_abc123" response = requests.put( f"https://api.aitronos.com/v1/analytics/usage/limits/{org_id}", headers={"X-API-Key": api_key}, json={ "monthly_api_limit": 10000.00, "total_api_key_limit": 7000.00, "api_key_id": "apikey_def456", "api_key_limit": 5000.00 } ) data = response.json() print(data["message"]) ``` ```javascript const response = await fetch( "https://api.aitronos.com/v1/analytics/usage/limits/org_abc123", { method: "PUT", headers: { "X-API-Key": process.env.FREDDY_API_KEY, "Content-Type": "application/json" }, body: JSON.stringify({ monthly_api_limit: 10000.00, total_api_key_limit: 7000.00, api_key_id: "apikey_def456", api_key_limit: 5000.00 }) } ); const data = await response.json(); console.log(data.message); ``` **Response:** 200 OK ```json { "success": true, "message": "Limits updated successfully", "updated_limits": { "organization_limit": 10000.00, "total_api_key_limit": 7000.00, "api_key_limit": 5000.00 } } ``` 422 Unprocessable Entity ```json { "success": false, "error": { "code": "INVALID_INPUT", "message": "Limit must be a positive number greater than zero", "system_message": "Validation error", "type": "client_error", "status": 422, "details": { "field": "monthly_api_limit", "value": -100 }, "trace_id": "abc-123-def", "timestamp": "2025-11-19T10:30:00Z" } } ``` 422 Limit Hierarchy Violation ```json { "success": false, "error": { "code": "INVALID_INPUT", "message": "Total API key limit (8000.00 CHF) cannot exceed organization limit (7000.00 CHF)", "system_message": "Validation error", "type": "client_error", "status": 422, "details": { "total_api_key_limit": 8000.00, "organization_limit": 7000.00 }, "trace_id": "abc-123-def", "timestamp": "2025-11-19T10:30:00Z" } } ``` 422 No Fields Provided ```json { "success": false, "error": { "code": "INVALID_INPUT", "message": "At least one limit must be provided", "system_message": "Validation error", "type": "client_error", "status": 422, "details": {}, "trace_id": "def-456-ghi", "timestamp": "2025-11-19T10:30:00Z" } } ``` 404 Not Found ```json { "success": false, "error": { "code": "API_KEY_NOT_FOUND", "message": "API key not found", "system_message": "API key not found", "type": "client_error", "status": 404, "details": { "api_key_id": "apikey_123" }, "trace_id": "ghi-789-jkl", "timestamp": "2025-11-19T10:30:00Z" } } ``` 403 Forbidden ```json { "success": false, "error": { "code": "ORGANIZATION_ACCESS_DENIED", "message": "API key does not belong to this organization", "system_message": "Authorization error", "type": "client_error", "status": 403, "details": { "api_key_id": "apikey_123", "organization_id": "org_456" }, "trace_id": "jkl-012-mno", "timestamp": "2025-11-19T10:30:00Z" } } ```