Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dashscope/applications/agentstudio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
validate_region,
validate_workspace_id,
)
from dashscope.applications.agentstudio.resources.usage import (
Usage,
AsyncUsage,
)
from dashscope.applications.agentstudio.resources.agents import (
Agents,
AsyncAgents,
Expand Down Expand Up @@ -213,6 +217,7 @@ def __init__(
self.memory_stores = MemoryStores(self)
self.webhook_endpoints = WebhookEndpoints(self)
self.security = Security(self)
self.usage = Usage(self)

def close(self) -> None:
self.transport.close()
Expand Down Expand Up @@ -295,6 +300,7 @@ def __init__(
self.memory_stores = AsyncMemoryStores(self)
self.webhook_endpoints = AsyncWebhookEndpoints(self)
self.security = AsyncSecurity(self)
self.usage = AsyncUsage(self)

async def aclose(self) -> None:
await self.transport.aclose()
Expand Down
66 changes: 66 additions & 0 deletions dashscope/applications/agentstudio/resources/usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
# Copyright (c) Alibaba, Inc. and its affiliates.
"""Usage summary and trend queries for Managed Agents."""

from __future__ import annotations

from typing import Any, Dict

_PATH_USAGE_SUMMARY = "/usage/summary"
_PATH_USAGE_TREND = "/usage/trend"


class Usage:
"""Read workspace, agent, and session usage."""

def __init__(self, client) -> None:
self._client = client

def summary(self, **params: Any) -> Dict[str, Any]:
"""Query usage totals and model/tool breakdowns (``POST /usage/summary``).

Pass the API's snake_case body fields as keyword arguments. The
service validates dimension-specific parameter combinations.
"""
resp = self._client.transport.request(
"POST",
_PATH_USAGE_SUMMARY,
json=dict(params),
)
return resp.data

def trend(self, **params: Any) -> Dict[str, Any]:
"""Query paginated usage buckets (``POST /usage/trend``).

Pass the API's snake_case body fields as keyword arguments. To fetch
another page, pass the returned ``next_page_token`` as ``page_token``.
"""
resp = self._client.transport.request(
"POST",
_PATH_USAGE_TREND,
json=dict(params),
)
return resp.data


class AsyncUsage:
"""Async usage summary and trend queries."""

def __init__(self, client) -> None:
self._client = client

async def summary(self, **params: Any) -> Dict[str, Any]:
resp = await self._client.transport.request(
"POST",
_PATH_USAGE_SUMMARY,
json=dict(params),
)
return resp.data

async def trend(self, **params: Any) -> Dict[str, Any]:
resp = await self._client.transport.request(
"POST",
_PATH_USAGE_TREND,
json=dict(params),
)
return resp.data
Loading
Loading