Budgets
List Budgets
Returns budgets visible to the current workspace, ordered by creation time with the newest first. Supports filtering by scope kind, scope target id, period, and active state, plus an optional free-text query that searches across denormalized target names via Typesense.from orq_ai_sdk import Orq
import os
with Orq(
api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:
res = orq.budgets.list()
# Handle response
print(res)
import { Orq } from "@orq-ai/node";
const orq = new Orq({
apiKey: process.env["ORQ_API_KEY"] ?? "",
});
async function run() {
const result = await orq.budgets.list();
console.log(result);
}
run();
Show Parameters
Show Parameters
{
"limit": Optional[int],
"starting_after": Optional[str],
"ending_before": Optional[str],
"scope_kind": List[Literal["BUDGET_SCOPE_KIND_UNSPECIFIED", "BUDGET_SCOPE_KIND_WORKSPACE", "BUDGET_SCOPE_KIND_PROJECT", "BUDGET_SCOPE_KIND_IDENTITY", "BUDGET_SCOPE_KIND_API_KEY", "BUDGET_SCOPE_KIND_PROVIDER", "BUDGET_SCOPE_KIND_MODEL"]],
"scope_target_id": Optional[str],
"is_active": Optional[bool],
"period": List[Literal["BUDGET_PERIOD_UNSPECIFIED", "BUDGET_PERIOD_DAILY", "BUDGET_PERIOD_WEEKLY", "BUDGET_PERIOD_MONTHLY", "BUDGET_PERIOD_YEARLY", "BUDGET_PERIOD_ONE_TIME"]],
"query": Optional[str],
"sort_by": Optional[Literal["BUDGET_SORT_FIELD_UNSPECIFIED", "BUDGET_SORT_FIELD_EXPIRES_AT", "BUDGET_SORT_FIELD_CREATED_AT", "BUDGET_SORT_FIELD_UPDATED_AT"]],
}
{
limit?: number;
startingAfter?: string;
endingBefore?: string;
scopeKind?: string;
scopeTargetId?: string;
isActive?: boolean;
period?: string;
query?: string;
sortBy?: string;
}
Show Response
Show Response
{
"object": Optional[str],
"data": { # optional
"budget_id": Optional[str],
"scope": { # optional
"workspace": {}, # optional
"project": { # optional
"project_id": Optional[str],
},
"identity": { # optional
"identity_external_id": Optional[str],
},
"api_key": { # optional
"api_key_id": Optional[str],
},
"provider": { # optional
"provider": Optional[str],
},
"model": { # optional
"model_id": Optional[str],
},
},
"match": { # optional
"cel": Optional[str],
},
"limits": { # optional
"period": Optional[Literal["BUDGET_PERIOD_UNSPECIFIED", "BUDGET_PERIOD_DAILY", "BUDGET_PERIOD_WEEKLY", "BUDGET_PERIOD_MONTHLY", "BUDGET_PERIOD_YEARLY", "BUDGET_PERIOD_ONE_TIME"]],
"amount": Optional[float],
"token_limit": Optional[float],
},
"rate_limit": { # optional
"requests_per_minute": Optional[int],
},
"is_active": Optional[bool],
"expires_at": date,
"created_at": date,
"updated_at": date,
"usage": { # optional
"amount": Optional[float],
"tokens": Optional[float],
"requests": Optional[int],
},
},
"has_more": Optional[bool],
}
{
object?: string;
data?: {
budgetId?: string;
scope?: {
workspace?: {};
project?: {
projectId?: string;
};
identity?: {
identityExternalId?: string;
};
apiKey?: {
apiKeyId?: string;
};
provider?: {
provider?: string;
};
model?: {
modelId?: string;
};
};
match?: {
cel?: string;
};
limits?: {
period?: string;
amount?: number;
tokenLimit?: number;
};
rateLimit?: {
requestsPerMinute?: number;
};
isActive?: boolean;
expiresAt?: Date;
createdAt?: Date;
updatedAt?: Date;
usage?: {
amount?: number;
tokens?: number;
requests?: number;
};
};
hasMore?: boolean;
}
Create a Budget
Creates a new budget in the workspace. Exactly one scope variant must be set (workspace / project / identity / api_key / provider / model). At least one oflimits.amount, limits.token_limit, or rate_limit.requests_per_minute MUST be provided. Uniqueness is enforced across (workspace_id, scope_kind, scope_target_id).
from orq_ai_sdk import Orq
import os
with Orq(
api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:
res = orq.budgets.create()
# Handle response
print(res)
import { Orq } from "@orq-ai/node";
const orq = new Orq({
apiKey: process.env["ORQ_API_KEY"] ?? "",
});
async function run() {
const result = await orq.budgets.create({});
console.log(result);
}
run();
Show Parameters
Show Parameters
{
"scope": { # optional
"workspace": {}, # optional
"project": { # optional
"project_id": Optional[str],
},
"identity": { # optional
"identity_external_id": Optional[str],
},
"api_key": { # optional
"api_key_id": Optional[str],
},
"provider": { # optional
"provider": Optional[str],
},
"model": { # optional
"model_id": Optional[str],
},
},
"match": { # optional
"cel": Optional[str],
},
"limits": { # optional
"period": Optional[Literal["BUDGET_PERIOD_UNSPECIFIED", "BUDGET_PERIOD_DAILY", "BUDGET_PERIOD_WEEKLY", "BUDGET_PERIOD_MONTHLY", "BUDGET_PERIOD_YEARLY", "BUDGET_PERIOD_ONE_TIME"]],
"amount": Optional[float],
"token_limit": Optional[float],
},
"rate_limit": { # optional
"requests_per_minute": Optional[int],
},
"is_active": Optional[bool],
"expires_at": date,
}
{
scope?: {
workspace?: {};
project?: {
projectId?: string;
};
identity?: {
identityExternalId?: string;
};
apiKey?: {
apiKeyId?: string;
};
provider?: {
provider?: string;
};
model?: {
modelId?: string;
};
};
match?: {
cel?: string;
};
limits?: {
period?: string;
amount?: number;
tokenLimit?: number;
};
rateLimit?: {
requestsPerMinute?: number;
};
isActive?: boolean;
expiresAt?: Date;
}
Show Response
Show Response
{
"budget": { # optional
"budget_id": Optional[str],
"scope": { # optional
"workspace": {}, # optional
"project": { # optional
"project_id": Optional[str],
},
"identity": { # optional
"identity_external_id": Optional[str],
},
"api_key": { # optional
"api_key_id": Optional[str],
},
"provider": { # optional
"provider": Optional[str],
},
"model": { # optional
"model_id": Optional[str],
},
},
"match": { # optional
"cel": Optional[str],
},
"limits": { # optional
"period": Optional[Literal["BUDGET_PERIOD_UNSPECIFIED", "BUDGET_PERIOD_DAILY", "BUDGET_PERIOD_WEEKLY", "BUDGET_PERIOD_MONTHLY", "BUDGET_PERIOD_YEARLY", "BUDGET_PERIOD_ONE_TIME"]],
"amount": Optional[float],
"token_limit": Optional[float],
},
"rate_limit": { # optional
"requests_per_minute": Optional[int],
},
"is_active": Optional[bool],
"expires_at": date,
"created_at": date,
"updated_at": date,
"usage": { # optional
"amount": Optional[float],
"tokens": Optional[float],
"requests": Optional[int],
},
},
}
{
budget?: {
budgetId?: string;
scope?: {
workspace?: {};
project?: {
projectId?: string;
};
identity?: {
identityExternalId?: string;
};
apiKey?: {
apiKeyId?: string;
};
provider?: {
provider?: string;
};
model?: {
modelId?: string;
};
};
match?: {
cel?: string;
};
limits?: {
period?: string;
amount?: number;
tokenLimit?: number;
};
rateLimit?: {
requestsPerMinute?: number;
};
isActive?: boolean;
expiresAt?: Date;
createdAt?: Date;
updatedAt?: Date;
usage?: {
amount?: number;
tokens?: number;
requests?: number;
};
};
}
Check a Budget
Internal endpoint used by the gateway to resolve applicable budgets and check enforcement gates for a request. Returns allowed/rejected status with dimension info for rate-limit headers.from orq_ai_sdk import Orq
import os
with Orq(
api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:
res = orq.budgets.check()
# Handle response
print(res)
import { Orq } from "@orq-ai/node";
const orq = new Orq({
apiKey: process.env["ORQ_API_KEY"] ?? "",
});
async function run() {
const result = await orq.budgets.check({});
console.log(result);
}
run();
Show Parameters
Show Parameters
{
"api_key_id": Optional[str],
"project_id": Optional[str],
"identity_external_id": Optional[str],
"provider": Optional[str],
"model_id": Optional[str],
"metadata": {}, # optional
"headers": Dict[str, str],
}
{
apiKeyId?: string;
projectId?: string;
identityExternalId?: string;
provider?: string;
modelId?: string;
metadata?: {};
headers?: Record<string, string>;
}
Show Response
Show Response
{
"allowed": Optional[bool],
"rejection": { # optional
"scope_kind": Optional[str],
"scope_target_id": Optional[str],
"dimension": Optional[str],
"code": Optional[str],
"message": Optional[str],
},
"cost": { # optional
"limit": Optional[float],
"remaining": Optional[float],
"reset_seconds": Optional[int],
},
"tokens": { # optional
"limit": Optional[float],
"remaining": Optional[float],
"reset_seconds": Optional[int],
},
"requests": { # optional
"limit": Optional[float],
"remaining": Optional[float],
"reset_seconds": Optional[int],
},
}
{
allowed?: boolean;
rejection?: {
scopeKind?: string;
scopeTargetId?: string;
dimension?: string;
code?: string;
message?: string;
};
cost?: {
limit?: number;
remaining?: number;
resetSeconds?: number;
};
tokens?: {
limit?: number;
remaining?: number;
resetSeconds?: number;
};
requests?: {
limit?: number;
remaining?: number;
resetSeconds?: number;
};
}
Retrieve a Budget
Retrieves the metadata for an existing budget by its unique identifier. ReturnsNotFound when the budget does not exist in the caller’s workspace.
from orq_ai_sdk import Orq
import os
with Orq(
api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:
res = orq.budgets.get(budget_id="<id>")
# Handle response
print(res)
import { Orq } from "@orq-ai/node";
const orq = new Orq({
apiKey: process.env["ORQ_API_KEY"] ?? "",
});
async function run() {
const result = await orq.budgets.get({
budgetId: "<id>",
});
console.log(result);
}
run();
Show Parameters
Show Parameters
{
"budget_id": str, # required
}
{
budgetId: string; // required
}
Show Response
Show Response
{
"budget": { # optional
"budget_id": Optional[str],
"scope": { # optional
"workspace": {}, # optional
"project": { # optional
"project_id": Optional[str],
},
"identity": { # optional
"identity_external_id": Optional[str],
},
"api_key": { # optional
"api_key_id": Optional[str],
},
"provider": { # optional
"provider": Optional[str],
},
"model": { # optional
"model_id": Optional[str],
},
},
"match": { # optional
"cel": Optional[str],
},
"limits": { # optional
"period": Optional[Literal["BUDGET_PERIOD_UNSPECIFIED", "BUDGET_PERIOD_DAILY", "BUDGET_PERIOD_WEEKLY", "BUDGET_PERIOD_MONTHLY", "BUDGET_PERIOD_YEARLY", "BUDGET_PERIOD_ONE_TIME"]],
"amount": Optional[float],
"token_limit": Optional[float],
},
"rate_limit": { # optional
"requests_per_minute": Optional[int],
},
"is_active": Optional[bool],
"expires_at": date,
"created_at": date,
"updated_at": date,
"usage": { # optional
"amount": Optional[float],
"tokens": Optional[float],
"requests": Optional[int],
},
},
}
{
budget?: {
budgetId?: string;
scope?: {
workspace?: {};
project?: {
projectId?: string;
};
identity?: {
identityExternalId?: string;
};
apiKey?: {
apiKeyId?: string;
};
provider?: {
provider?: string;
};
model?: {
modelId?: string;
};
};
match?: {
cel?: string;
};
limits?: {
period?: string;
amount?: number;
tokenLimit?: number;
};
rateLimit?: {
requestsPerMinute?: number;
};
isActive?: boolean;
expiresAt?: Date;
createdAt?: Date;
updatedAt?: Date;
usage?: {
amount?: number;
tokens?: number;
requests?: number;
};
};
}
Delete a Budget
Permanently deletes a budget. Consumption counters in Redis for this budget are cleared immediately. The response body is empty on success.from orq_ai_sdk import Orq
import os
with Orq(
api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:
res = orq.budgets.delete(budget_id="<id>")
# Handle response
print(res)
import { Orq } from "@orq-ai/node";
const orq = new Orq({
apiKey: process.env["ORQ_API_KEY"] ?? "",
});
async function run() {
const result = await orq.budgets.delete({
budgetId: "<id>",
});
console.log(result);
}
run();
Show Parameters
Show Parameters
{
"budget_id": str, # required
}
{
budgetId: string; // required
}
Update a Budget
Updates mutable fields of a budget: limits, rate limit, activation, and expiration. The scope is immutable: to change a budget’s target, delete and recreate it. Omitted fields keep their current values.from orq_ai_sdk import Orq
import os
with Orq(
api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:
res = orq.budgets.update(budget_id="<id>")
# Handle response
print(res)
import { Orq } from "@orq-ai/node";
const orq = new Orq({
apiKey: process.env["ORQ_API_KEY"] ?? "",
});
async function run() {
const result = await orq.budgets.update({
budgetId: "<id>",
updateBudgetRequest: {},
});
console.log(result);
}
run();
Show Parameters
Show Parameters
{
"budget_id": str, # required
"limits": { # optional
"period": Optional[Literal["BUDGET_PERIOD_UNSPECIFIED", "BUDGET_PERIOD_DAILY", "BUDGET_PERIOD_WEEKLY", "BUDGET_PERIOD_MONTHLY", "BUDGET_PERIOD_YEARLY", "BUDGET_PERIOD_ONE_TIME"]],
"amount": Optional[float],
"token_limit": Optional[float],
},
"rate_limit": { # optional
"requests_per_minute": Optional[int],
},
"is_active": Optional[bool],
"expires_at": date,
"clear_expires_at": Optional[bool],
"match": { # optional
"cel": Optional[str],
},
}
{
budgetId: string; // required
updateBudgetRequest: { // required
limits?: {
period?: string;
amount?: number;
tokenLimit?: number;
};
rateLimit?: {
requestsPerMinute?: number;
};
isActive?: boolean;
expiresAt?: Date;
clearExpiresAt?: boolean;
match?: {
cel?: string;
};
};
}
Show Response
Show Response
{
"budget": { # optional
"budget_id": Optional[str],
"scope": { # optional
"workspace": {}, # optional
"project": { # optional
"project_id": Optional[str],
},
"identity": { # optional
"identity_external_id": Optional[str],
},
"api_key": { # optional
"api_key_id": Optional[str],
},
"provider": { # optional
"provider": Optional[str],
},
"model": { # optional
"model_id": Optional[str],
},
},
"match": { # optional
"cel": Optional[str],
},
"limits": { # optional
"period": Optional[Literal["BUDGET_PERIOD_UNSPECIFIED", "BUDGET_PERIOD_DAILY", "BUDGET_PERIOD_WEEKLY", "BUDGET_PERIOD_MONTHLY", "BUDGET_PERIOD_YEARLY", "BUDGET_PERIOD_ONE_TIME"]],
"amount": Optional[float],
"token_limit": Optional[float],
},
"rate_limit": { # optional
"requests_per_minute": Optional[int],
},
"is_active": Optional[bool],
"expires_at": date,
"created_at": date,
"updated_at": date,
"usage": { # optional
"amount": Optional[float],
"tokens": Optional[float],
"requests": Optional[int],
},
},
}
{
budget?: {
budgetId?: string;
scope?: {
workspace?: {};
project?: {
projectId?: string;
};
identity?: {
identityExternalId?: string;
};
apiKey?: {
apiKeyId?: string;
};
provider?: {
provider?: string;
};
model?: {
modelId?: string;
};
};
match?: {
cel?: string;
};
limits?: {
period?: string;
amount?: number;
tokenLimit?: number;
};
rateLimit?: {
requestsPerMinute?: number;
};
isActive?: boolean;
expiresAt?: Date;
createdAt?: Date;
updatedAt?: Date;
usage?: {
amount?: number;
tokens?: number;
requests?: number;
};
};
}
Get Consumption
Returns the current-period cost, token, and per-minute request counters for the budget. Values reflect the live Redis state for the active period bucket.from orq_ai_sdk import Orq
import os
with Orq(
api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:
res = orq.budgets.get_consumption(budget_id="<id>")
# Handle response
print(res)
import { Orq } from "@orq-ai/node";
const orq = new Orq({
apiKey: process.env["ORQ_API_KEY"] ?? "",
});
async function run() {
const result = await orq.budgets.getConsumption({
budgetId: "<id>",
});
console.log(result);
}
run();
Show Parameters
Show Parameters
{
"budget_id": str, # required
}
{
budgetId: string; // required
}
Show Response
Show Response
{
"budget_id": Optional[str],
"period": Optional[Literal["BUDGET_PERIOD_UNSPECIFIED", "BUDGET_PERIOD_DAILY", "BUDGET_PERIOD_WEEKLY", "BUDGET_PERIOD_MONTHLY", "BUDGET_PERIOD_YEARLY", "BUDGET_PERIOD_ONE_TIME"]],
"period_date": Optional[str],
"cost": Optional[float],
"tokens": Optional[float],
"requests_in_window": Optional[int],
}
{
budgetId?: string;
period?: string;
periodDate?: string;
cost?: number;
tokens?: number;
requestsInWindow?: number;
}
Reset Consumption
Clears the current-period cost, token, and request counters for the budget. The budget record itself is preserved; only the Redis counters are reset.from orq_ai_sdk import Orq
import os
with Orq(
api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:
res = orq.budgets.reset_consumption(budget_id="<id>", reset_budget_consumption_request={})
# Handle response
print(res)
import { Orq } from "@orq-ai/node";
const orq = new Orq({
apiKey: process.env["ORQ_API_KEY"] ?? "",
});
async function run() {
const result = await orq.budgets.resetConsumption({
budgetId: "<id>",
resetBudgetConsumptionRequest: {},
});
console.log(result);
}
run();
Show Parameters
Show Parameters
{
"budget_id": str, # required
"reset_budget_consumption_request": {}, # required
}
{
budgetId: string; // required
resetBudgetConsumptionRequest: {}; // required
}
Show Response
Show Response
{
"budget": { # optional
"budget_id": Optional[str],
"scope": { # optional
"workspace": {}, # optional
"project": { # optional
"project_id": Optional[str],
},
"identity": { # optional
"identity_external_id": Optional[str],
},
"api_key": { # optional
"api_key_id": Optional[str],
},
"provider": { # optional
"provider": Optional[str],
},
"model": { # optional
"model_id": Optional[str],
},
},
"match": { # optional
"cel": Optional[str],
},
"limits": { # optional
"period": Optional[Literal["BUDGET_PERIOD_UNSPECIFIED", "BUDGET_PERIOD_DAILY", "BUDGET_PERIOD_WEEKLY", "BUDGET_PERIOD_MONTHLY", "BUDGET_PERIOD_YEARLY", "BUDGET_PERIOD_ONE_TIME"]],
"amount": Optional[float],
"token_limit": Optional[float],
},
"rate_limit": { # optional
"requests_per_minute": Optional[int],
},
"is_active": Optional[bool],
"expires_at": date,
"created_at": date,
"updated_at": date,
"usage": { # optional
"amount": Optional[float],
"tokens": Optional[float],
"requests": Optional[int],
},
},
}
{
budget?: {
budgetId?: string;
scope?: {
workspace?: {};
project?: {
projectId?: string;
};
identity?: {
identityExternalId?: string;
};
apiKey?: {
apiKeyId?: string;
};
provider?: {
provider?: string;
};
model?: {
modelId?: string;
};
};
match?: {
cel?: string;
};
limits?: {
period?: string;
amount?: number;
tokenLimit?: number;
};
rateLimit?: {
requestsPerMinute?: number;
};
isActive?: boolean;
expiresAt?: Date;
createdAt?: Date;
updatedAt?: Date;
usage?: {
amount?: number;
tokens?: number;
requests?: number;
};
};
}