Budgets
Set an apikey budget
Creates or updates a budget for the apikey. One budget per (scope, owner); editing re-evaluates against live spend. Callable by cluster admins, or org admins for API keys in their own organization.
PUT
/
api
/
v1
/
budgeting
/
budgets
/
apikey
/
{apiKeyId}
CSharp (SDK)
using MeetKai.MKA1;
using MeetKai.MKA1.Types.Components;
using MeetKai.MKA1.Types.Requests;
using System.Collections.Generic;
var sdk = new SDK(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");
var res = await sdk.Budgets.SetApiKeyAsync(
apiKeyId: "<id>",
body: new SetApiKeyBudgetRequestBody() {
Period = SetApiKeyBudgetPeriodRequest.Weekly,
Limit = 3281.35D,
Thresholds = new List<SetApiKeyBudgetThresholdRequest>() {
new SetApiKeyBudgetThresholdRequest() {
Pct = 793338,
Action = SetApiKeyBudgetActionRequest.Alert,
},
},
}
);
// handle responsefrom meetkai_mka1 import SDK
with SDK(
bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
) as sdk:
res = sdk.budgets.set_api_key(api_key_id="<id>", period="weekly", limit=3281.35, thresholds=[
{
"pct": 793338,
"action": "alert",
},
], owner="org")
# Handle response
print(res)import { SDK } from "@meetkai/mka1";
const sdk = new SDK({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await sdk.budgets.setApiKey({
apiKeyId: "<id>",
requestBody: {
period: "weekly",
limit: 3281.35,
thresholds: [
{
pct: 793338,
action: "alert",
},
],
},
});
console.log(result);
}
run();package main
import(
"context"
mka1 "github.com/MeetKai/mka1-sdks/go"
"github.com/MeetKai/mka1-sdks/go/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := mka1.New(
mka1.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Budgets.SetAPIKey(ctx, "<id>", operations.SetAPIKeyBudgetRequestBody{
Period: operations.SetAPIKeyBudgetPeriodRequestWeekly,
Limit: 7295.26,
Thresholds: []operations.SetAPIKeyBudgetThresholdRequest{},
})
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}curl --request PUT \
--url https://apigw.mka1.com/api/v1/budgeting/budgets/apikey/{apiKeyId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"limit": 123,
"thresholds": [
{
"pct": 50
}
],
"owner": "org",
"webhook_url": "<string>",
"webhook_secret": "<string>"
}
'const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
limit: 123,
thresholds: [{pct: 50}],
owner: 'org',
webhook_url: '<string>',
webhook_secret: '<string>'
})
};
fetch('https://apigw.mka1.com/api/v1/budgeting/budgets/apikey/{apiKeyId}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://apigw.mka1.com/api/v1/budgeting/budgets/apikey/{apiKeyId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'limit' => 123,
'thresholds' => [
[
'pct' => 50
]
],
'owner' => 'org',
'webhook_url' => '<string>',
'webhook_secret' => '<string>'
]),
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;
}HttpResponse<String> response = Unirest.put("https://apigw.mka1.com/api/v1/budgeting/budgets/apikey/{apiKeyId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"limit\": 123,\n \"thresholds\": [\n {\n \"pct\": 50\n }\n ],\n \"owner\": \"org\",\n \"webhook_url\": \"<string>\",\n \"webhook_secret\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://apigw.mka1.com/api/v1/budgeting/budgets/apikey/{apiKeyId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"limit\": 123,\n \"thresholds\": [\n {\n \"pct\": 50\n }\n ],\n \"owner\": \"org\",\n \"webhook_url\": \"<string>\",\n \"webhook_secret\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"scope": "org",
"scope_id": "<string>",
"scope_org_id": "<string>",
"owner": "cluster",
"period": "daily",
"limit": 123,
"thresholds": [
{
"pct": 50,
"action": "alert"
}
],
"alert_webhook_url": "<string>",
"spend": {
"window": "<string>",
"cost_spent": 123,
"limit": 123,
"pct": 0,
"status": "ok"
}
}Authorizations
Body
application/json
Response
200 - application/json
OK
Was this page helpful?
⌘I
CSharp (SDK)
using MeetKai.MKA1;
using MeetKai.MKA1.Types.Components;
using MeetKai.MKA1.Types.Requests;
using System.Collections.Generic;
var sdk = new SDK(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");
var res = await sdk.Budgets.SetApiKeyAsync(
apiKeyId: "<id>",
body: new SetApiKeyBudgetRequestBody() {
Period = SetApiKeyBudgetPeriodRequest.Weekly,
Limit = 3281.35D,
Thresholds = new List<SetApiKeyBudgetThresholdRequest>() {
new SetApiKeyBudgetThresholdRequest() {
Pct = 793338,
Action = SetApiKeyBudgetActionRequest.Alert,
},
},
}
);
// handle responsefrom meetkai_mka1 import SDK
with SDK(
bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
) as sdk:
res = sdk.budgets.set_api_key(api_key_id="<id>", period="weekly", limit=3281.35, thresholds=[
{
"pct": 793338,
"action": "alert",
},
], owner="org")
# Handle response
print(res)import { SDK } from "@meetkai/mka1";
const sdk = new SDK({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await sdk.budgets.setApiKey({
apiKeyId: "<id>",
requestBody: {
period: "weekly",
limit: 3281.35,
thresholds: [
{
pct: 793338,
action: "alert",
},
],
},
});
console.log(result);
}
run();package main
import(
"context"
mka1 "github.com/MeetKai/mka1-sdks/go"
"github.com/MeetKai/mka1-sdks/go/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := mka1.New(
mka1.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Budgets.SetAPIKey(ctx, "<id>", operations.SetAPIKeyBudgetRequestBody{
Period: operations.SetAPIKeyBudgetPeriodRequestWeekly,
Limit: 7295.26,
Thresholds: []operations.SetAPIKeyBudgetThresholdRequest{},
})
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}curl --request PUT \
--url https://apigw.mka1.com/api/v1/budgeting/budgets/apikey/{apiKeyId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"limit": 123,
"thresholds": [
{
"pct": 50
}
],
"owner": "org",
"webhook_url": "<string>",
"webhook_secret": "<string>"
}
'const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
limit: 123,
thresholds: [{pct: 50}],
owner: 'org',
webhook_url: '<string>',
webhook_secret: '<string>'
})
};
fetch('https://apigw.mka1.com/api/v1/budgeting/budgets/apikey/{apiKeyId}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://apigw.mka1.com/api/v1/budgeting/budgets/apikey/{apiKeyId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'limit' => 123,
'thresholds' => [
[
'pct' => 50
]
],
'owner' => 'org',
'webhook_url' => '<string>',
'webhook_secret' => '<string>'
]),
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;
}HttpResponse<String> response = Unirest.put("https://apigw.mka1.com/api/v1/budgeting/budgets/apikey/{apiKeyId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"limit\": 123,\n \"thresholds\": [\n {\n \"pct\": 50\n }\n ],\n \"owner\": \"org\",\n \"webhook_url\": \"<string>\",\n \"webhook_secret\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://apigw.mka1.com/api/v1/budgeting/budgets/apikey/{apiKeyId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"limit\": 123,\n \"thresholds\": [\n {\n \"pct\": 50\n }\n ],\n \"owner\": \"org\",\n \"webhook_url\": \"<string>\",\n \"webhook_secret\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"scope": "org",
"scope_id": "<string>",
"scope_org_id": "<string>",
"owner": "cluster",
"period": "daily",
"limit": 123,
"thresholds": [
{
"pct": 50,
"action": "alert"
}
],
"alert_webhook_url": "<string>",
"spend": {
"window": "<string>",
"cost_spent": 123,
"limit": 123,
"pct": 0,
"status": "ok"
}
}