إنشاء قاعدة إنفاق
ينشئ تنبيه إنفاق، ويمكن أن يحظر الطلبات بعد تجاوز حد معيّن.
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
enabled: true,
scope_id: '<string>',
window_hours: 360,
time_zone: '<string>',
base_amount_usd: 123,
base_amount_nanos: 123,
threshold_percents: [500],
threshold_amount_usd: 123,
threshold_amount_nanos: 123,
runway_days: 183,
spike_multiplier: 123,
spike_floor_usd: 123,
spike_floor_nanos: 123,
block_at_percent: 550,
block_at_amount_usd: 123,
block_at_amount_nanos: 123,
block_free_models: true,
cooldown_minutes: 21602,
destination_ids: ['3c90c3cc-0d44-4b50-8888-8dd25736052a']
})
};
fetch('https://api.phaseo.app/v1/spend-rules', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.phaseo.app/v1/spend-rules"
payload = {
"name": "<string>",
"enabled": True,
"scope_id": "<string>",
"window_hours": 360,
"time_zone": "<string>",
"base_amount_usd": 123,
"base_amount_nanos": 123,
"threshold_percents": [500],
"threshold_amount_usd": 123,
"threshold_amount_nanos": 123,
"runway_days": 183,
"spike_multiplier": 123,
"spike_floor_usd": 123,
"spike_floor_nanos": 123,
"block_at_percent": 550,
"block_at_amount_usd": 123,
"block_at_amount_nanos": 123,
"block_free_models": True,
"cooldown_minutes": 21602,
"destination_ids": ["3c90c3cc-0d44-4b50-8888-8dd25736052a"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)curl --request POST \
--url https://api.phaseo.app/v1/spend-rules \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"enabled": true,
"scope_id": "<string>",
"window_hours": 360,
"time_zone": "<string>",
"base_amount_usd": 123,
"base_amount_nanos": 123,
"threshold_percents": [
500
],
"threshold_amount_usd": 123,
"threshold_amount_nanos": 123,
"runway_days": 183,
"spike_multiplier": 123,
"spike_floor_usd": 123,
"spike_floor_nanos": 123,
"block_at_percent": 550,
"block_at_amount_usd": 123,
"block_at_amount_nanos": 123,
"block_free_models": true,
"cooldown_minutes": 21602,
"destination_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
]
}
'package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.phaseo.app/v1/spend-rules"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"enabled\": true,\n \"scope_id\": \"<string>\",\n \"window_hours\": 360,\n \"time_zone\": \"<string>\",\n \"base_amount_usd\": 123,\n \"base_amount_nanos\": 123,\n \"threshold_percents\": [\n 500\n ],\n \"threshold_amount_usd\": 123,\n \"threshold_amount_nanos\": 123,\n \"runway_days\": 183,\n \"spike_multiplier\": 123,\n \"spike_floor_usd\": 123,\n \"spike_floor_nanos\": 123,\n \"block_at_percent\": 550,\n \"block_at_amount_usd\": 123,\n \"block_at_amount_nanos\": 123,\n \"block_free_models\": true,\n \"cooldown_minutes\": 21602,\n \"destination_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.phaseo.app/v1/spend-rules")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"enabled\": true,\n \"scope_id\": \"<string>\",\n \"window_hours\": 360,\n \"time_zone\": \"<string>\",\n \"base_amount_usd\": 123,\n \"base_amount_nanos\": 123,\n \"threshold_percents\": [\n 500\n ],\n \"threshold_amount_usd\": 123,\n \"threshold_amount_nanos\": 123,\n \"runway_days\": 183,\n \"spike_multiplier\": 123,\n \"spike_floor_usd\": 123,\n \"spike_floor_nanos\": 123,\n \"block_at_percent\": 550,\n \"block_at_amount_usd\": 123,\n \"block_at_amount_nanos\": 123,\n \"block_free_models\": true,\n \"cooldown_minutes\": 21602,\n \"destination_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\n}")
.asString();<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.phaseo.app/v1/spend-rules",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => '<string>',
'enabled' => true,
'scope_id' => '<string>',
'window_hours' => 360,
'time_zone' => '<string>',
'base_amount_usd' => 123,
'base_amount_nanos' => 123,
'threshold_percents' => [
500
],
'threshold_amount_usd' => 123,
'threshold_amount_nanos' => 123,
'runway_days' => 183,
'spike_multiplier' => 123,
'spike_floor_usd' => 123,
'spike_floor_nanos' => 123,
'block_at_percent' => 550,
'block_at_amount_usd' => 123,
'block_at_amount_nanos' => 123,
'block_free_models' => true,
'cooldown_minutes' => 21602,
'destination_ids' => [
'3c90c3cc-0d44-4b50-8888-8dd25736052a'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}require 'uri'
require 'net/http'
url = URI("https://api.phaseo.app/v1/spend-rules")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"enabled\": true,\n \"scope_id\": \"<string>\",\n \"window_hours\": 360,\n \"time_zone\": \"<string>\",\n \"base_amount_usd\": 123,\n \"base_amount_nanos\": 123,\n \"threshold_percents\": [\n 500\n ],\n \"threshold_amount_usd\": 123,\n \"threshold_amount_nanos\": 123,\n \"runway_days\": 183,\n \"spike_multiplier\": 123,\n \"spike_floor_usd\": 123,\n \"spike_floor_nanos\": 123,\n \"block_at_percent\": 550,\n \"block_at_amount_usd\": 123,\n \"block_at_amount_nanos\": 123,\n \"block_free_models\": true,\n \"cooldown_minutes\": 21602,\n \"destination_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"workspace_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>",
"enabled": true,
"metric": "spend",
"evaluated": true,
"scope_type": "workspace",
"scope_id": "<string>",
"period": "day",
"window_hours": 360,
"time_zone": "<string>",
"base_kind": "amount",
"base_ref": "daily",
"base_amount_nanos": 123,
"base_amount_usd": 123,
"threshold_percents": [
500
],
"threshold_amount_nanos": 123,
"threshold_amount_usd": 123,
"runway_days": 183,
"spike_multiplier": 123,
"spike_floor_nanos": 123,
"spike_floor_usd": 123,
"action": "notify",
"block_at_percent": 550,
"block_at_amount_nanos": 123,
"block_at_amount_usd": 123,
"block_free_models": true,
"cooldown_minutes": 21602,
"destination_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"created_by": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "validation_error",
"message": "Unknown parameter: foo",
"type": "invalid_request_error",
"param": "foo"
},
"ok": false,
"code": "validation_error",
"message": "Human-readable error message",
"description": "Additional error details.",
"generation_id": "G-abc123",
"status_code": 502,
"error_type": "system",
"error_origin": "upstream",
"reason": "all_candidates_failed",
"attempt_count": 2,
"failed_providers": [
"google-ai-studio",
"openai"
],
"failed_statuses": [
403,
429
],
"upstream_error": {
"code": "PERMISSION_DENIED",
"message": "The caller does not have permission.",
"description": "<string>",
"param": "<string>"
},
"failure_sample": [
{
"provider": "<string>",
"type": "<string>",
"status": 123,
"upstream_error_code": "<string>",
"upstream_error_message": "<string>",
"upstream_error_description": "<string>",
"upstream_error_param": "<string>",
"upstream_payload_preview": "<string>",
"retryable": true
}
],
"provider_failure_diagnostics": {
"category": "credentials_not_configured",
"hint": "<string>",
"provider": "<string>"
},
"routing_diagnostics": {
"filterStages": [
{
"stage": "<string>",
"beforeCount": 123,
"afterCount": 123,
"droppedProviders": [
{
"providerId": "<string>",
"reason": "<string>"
}
]
}
]
},
"provider_candidate_diagnostics": {
"totalProviders": 123,
"supportsEndpointCount": 123,
"candidateCount": 123,
"droppedUnsupportedEndpoint": [
"<string>"
],
"droppedMissingAdapter": [
{
"providerId": "<string>",
"endpoint": "<string>"
}
]
},
"provider_enablement": {
"capability": "<string>",
"providersBefore": [
"<string>"
],
"providersAfter": [
"<string>"
],
"dropped": [
{
"providerId": "<string>",
"reason": "<string>"
}
]
},
"missing_pricing_providers": [
"<string>"
],
"provider_payment_required_provider": "openai",
"provider_payment_required_support_notice": "Our upstream provider billing appears to be unavailable. If this persists, contact support.",
"details": [
{}
]
}spend_rules:write. يجب أن يكون مستدعو OAuth مالكين أو مشرفين في مساحة العمل. أرسل كل مبلغ بالدولار الأمريكي (*_usd) أو بالنانودولار (*_nanos)، وليس بالاثنين. يمكن أن تحتوي مساحة العمل على 50 قاعدة إنفاق. راجع دليل تنبيهات الإنفاق لمعرفة المقاييس والأسس والنطاقات والفترات.الجسم
قاعدة إنفاق مراد إنشاؤها. الحقول name وmetric وperiod مطلوبة. تستخدم قواعد spike افتراضيًا مضاعفًا قدره 3x وحدًا أدنى قدره 5 دولارات.
spend: بلغ الإنفاق threshold_amount. budget_percent: بلغ الإنفاق threshold_percents من الأساس. forecast: يبلغ الإنفاق المتوقع حتى نهاية الفترة العتبة. spike: الإنفاق خلال آخر window_hours يساوي spike_multiplier مرة على الأقل من وسيط النافذة نفسها خلال الأيام السبعة السابقة، ولا يقل عن spike_floor. balance: ينخفض رصيد مساحة العمل أو مدة كفايته عن العتبة.
spend, budget_percent, forecast, spike, balance notify، أو التنبيه ثم الحظر عندما يبلغ الإنفاق block_at_percent من الأساس أو block_at_amount. الحظر يتم بأفضل جهد ويعمل بعد بلوغ الحد ببضع دقائق. ما دام الحظر متوقفًا في البوابة، تُرفض القاعدة التي ستبدأ الحظر برمز 400، والقاعدة التي تحظر بالفعل تكتفي بالتنبيه.
notify, block هل كانت هذه الصفحة مفيدة؟
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
enabled: true,
scope_id: '<string>',
window_hours: 360,
time_zone: '<string>',
base_amount_usd: 123,
base_amount_nanos: 123,
threshold_percents: [500],
threshold_amount_usd: 123,
threshold_amount_nanos: 123,
runway_days: 183,
spike_multiplier: 123,
spike_floor_usd: 123,
spike_floor_nanos: 123,
block_at_percent: 550,
block_at_amount_usd: 123,
block_at_amount_nanos: 123,
block_free_models: true,
cooldown_minutes: 21602,
destination_ids: ['3c90c3cc-0d44-4b50-8888-8dd25736052a']
})
};
fetch('https://api.phaseo.app/v1/spend-rules', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.phaseo.app/v1/spend-rules"
payload = {
"name": "<string>",
"enabled": True,
"scope_id": "<string>",
"window_hours": 360,
"time_zone": "<string>",
"base_amount_usd": 123,
"base_amount_nanos": 123,
"threshold_percents": [500],
"threshold_amount_usd": 123,
"threshold_amount_nanos": 123,
"runway_days": 183,
"spike_multiplier": 123,
"spike_floor_usd": 123,
"spike_floor_nanos": 123,
"block_at_percent": 550,
"block_at_amount_usd": 123,
"block_at_amount_nanos": 123,
"block_free_models": True,
"cooldown_minutes": 21602,
"destination_ids": ["3c90c3cc-0d44-4b50-8888-8dd25736052a"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)curl --request POST \
--url https://api.phaseo.app/v1/spend-rules \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"enabled": true,
"scope_id": "<string>",
"window_hours": 360,
"time_zone": "<string>",
"base_amount_usd": 123,
"base_amount_nanos": 123,
"threshold_percents": [
500
],
"threshold_amount_usd": 123,
"threshold_amount_nanos": 123,
"runway_days": 183,
"spike_multiplier": 123,
"spike_floor_usd": 123,
"spike_floor_nanos": 123,
"block_at_percent": 550,
"block_at_amount_usd": 123,
"block_at_amount_nanos": 123,
"block_free_models": true,
"cooldown_minutes": 21602,
"destination_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
]
}
'package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.phaseo.app/v1/spend-rules"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"enabled\": true,\n \"scope_id\": \"<string>\",\n \"window_hours\": 360,\n \"time_zone\": \"<string>\",\n \"base_amount_usd\": 123,\n \"base_amount_nanos\": 123,\n \"threshold_percents\": [\n 500\n ],\n \"threshold_amount_usd\": 123,\n \"threshold_amount_nanos\": 123,\n \"runway_days\": 183,\n \"spike_multiplier\": 123,\n \"spike_floor_usd\": 123,\n \"spike_floor_nanos\": 123,\n \"block_at_percent\": 550,\n \"block_at_amount_usd\": 123,\n \"block_at_amount_nanos\": 123,\n \"block_free_models\": true,\n \"cooldown_minutes\": 21602,\n \"destination_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.phaseo.app/v1/spend-rules")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"enabled\": true,\n \"scope_id\": \"<string>\",\n \"window_hours\": 360,\n \"time_zone\": \"<string>\",\n \"base_amount_usd\": 123,\n \"base_amount_nanos\": 123,\n \"threshold_percents\": [\n 500\n ],\n \"threshold_amount_usd\": 123,\n \"threshold_amount_nanos\": 123,\n \"runway_days\": 183,\n \"spike_multiplier\": 123,\n \"spike_floor_usd\": 123,\n \"spike_floor_nanos\": 123,\n \"block_at_percent\": 550,\n \"block_at_amount_usd\": 123,\n \"block_at_amount_nanos\": 123,\n \"block_free_models\": true,\n \"cooldown_minutes\": 21602,\n \"destination_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\n}")
.asString();<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.phaseo.app/v1/spend-rules",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => '<string>',
'enabled' => true,
'scope_id' => '<string>',
'window_hours' => 360,
'time_zone' => '<string>',
'base_amount_usd' => 123,
'base_amount_nanos' => 123,
'threshold_percents' => [
500
],
'threshold_amount_usd' => 123,
'threshold_amount_nanos' => 123,
'runway_days' => 183,
'spike_multiplier' => 123,
'spike_floor_usd' => 123,
'spike_floor_nanos' => 123,
'block_at_percent' => 550,
'block_at_amount_usd' => 123,
'block_at_amount_nanos' => 123,
'block_free_models' => true,
'cooldown_minutes' => 21602,
'destination_ids' => [
'3c90c3cc-0d44-4b50-8888-8dd25736052a'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}require 'uri'
require 'net/http'
url = URI("https://api.phaseo.app/v1/spend-rules")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"enabled\": true,\n \"scope_id\": \"<string>\",\n \"window_hours\": 360,\n \"time_zone\": \"<string>\",\n \"base_amount_usd\": 123,\n \"base_amount_nanos\": 123,\n \"threshold_percents\": [\n 500\n ],\n \"threshold_amount_usd\": 123,\n \"threshold_amount_nanos\": 123,\n \"runway_days\": 183,\n \"spike_multiplier\": 123,\n \"spike_floor_usd\": 123,\n \"spike_floor_nanos\": 123,\n \"block_at_percent\": 550,\n \"block_at_amount_usd\": 123,\n \"block_at_amount_nanos\": 123,\n \"block_free_models\": true,\n \"cooldown_minutes\": 21602,\n \"destination_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"workspace_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>",
"enabled": true,
"metric": "spend",
"evaluated": true,
"scope_type": "workspace",
"scope_id": "<string>",
"period": "day",
"window_hours": 360,
"time_zone": "<string>",
"base_kind": "amount",
"base_ref": "daily",
"base_amount_nanos": 123,
"base_amount_usd": 123,
"threshold_percents": [
500
],
"threshold_amount_nanos": 123,
"threshold_amount_usd": 123,
"runway_days": 183,
"spike_multiplier": 123,
"spike_floor_nanos": 123,
"spike_floor_usd": 123,
"action": "notify",
"block_at_percent": 550,
"block_at_amount_nanos": 123,
"block_at_amount_usd": 123,
"block_free_models": true,
"cooldown_minutes": 21602,
"destination_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"created_by": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "validation_error",
"message": "Unknown parameter: foo",
"type": "invalid_request_error",
"param": "foo"
},
"ok": false,
"code": "validation_error",
"message": "Human-readable error message",
"description": "Additional error details.",
"generation_id": "G-abc123",
"status_code": 502,
"error_type": "system",
"error_origin": "upstream",
"reason": "all_candidates_failed",
"attempt_count": 2,
"failed_providers": [
"google-ai-studio",
"openai"
],
"failed_statuses": [
403,
429
],
"upstream_error": {
"code": "PERMISSION_DENIED",
"message": "The caller does not have permission.",
"description": "<string>",
"param": "<string>"
},
"failure_sample": [
{
"provider": "<string>",
"type": "<string>",
"status": 123,
"upstream_error_code": "<string>",
"upstream_error_message": "<string>",
"upstream_error_description": "<string>",
"upstream_error_param": "<string>",
"upstream_payload_preview": "<string>",
"retryable": true
}
],
"provider_failure_diagnostics": {
"category": "credentials_not_configured",
"hint": "<string>",
"provider": "<string>"
},
"routing_diagnostics": {
"filterStages": [
{
"stage": "<string>",
"beforeCount": 123,
"afterCount": 123,
"droppedProviders": [
{
"providerId": "<string>",
"reason": "<string>"
}
]
}
]
},
"provider_candidate_diagnostics": {
"totalProviders": 123,
"supportsEndpointCount": 123,
"candidateCount": 123,
"droppedUnsupportedEndpoint": [
"<string>"
],
"droppedMissingAdapter": [
{
"providerId": "<string>",
"endpoint": "<string>"
}
]
},
"provider_enablement": {
"capability": "<string>",
"providersBefore": [
"<string>"
],
"providersAfter": [
"<string>"
],
"dropped": [
{
"providerId": "<string>",
"reason": "<string>"
}
]
},
"missing_pricing_providers": [
"<string>"
],
"provider_payment_required_provider": "openai",
"provider_payment_required_support_notice": "Our upstream provider billing appears to be unavailable. If this persists, contact support.",
"details": [
{}
]
}