Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(platform/admin): sync openapi.json with backend schema

Zamil Majdy54eaf7b818dd
diff --git a/autogpt_platform/backend/backend/api/features/admin/platform_cost_routes.py b/autogpt_platform/backend/backend/api/features/admin/platform_cost_routes.py
index f9b8aa817a..70e7772790 100644
--- a/autogpt_platform/backend/backend/api/features/admin/platform_cost_routes.py
+++ b/autogpt_platform/backend/backend/api/features/admin/platform_cost_routes.py
@@ -40,6 +40,9 @@ async def get_cost_dashboard(
end: datetime | None = Query(None),
provider: str | None = Query(None),
user_id: str | None = Query(None),
+ model: str | None = Query(None),
+ block_name: str | None = Query(None),
+ tracking_type: str | None = Query(None),
):
logger.info("Admin %s fetching platform cost dashboard", admin_user_id)
return await get_platform_cost_dashboard(
@@ -47,6 +50,9 @@ async def get_cost_dashboard(
end=end,
provider=provider,
user_id=user_id,
+ model=model,
+ block_name=block_name,
+ tracking_type=tracking_type,
)
@@ -63,6 +69,9 @@ async def get_cost_logs(
user_id: str | None = Query(None),
page: int = Query(1, ge=1),
page_size: int = Query(50, ge=1, le=200),
+ model: str | None = Query(None),
+ block_name: str | None = Query(None),
+ tracking_type: str | None = Query(None),
):
logger.info("Admin %s fetching platform cost logs", admin_user_id)
logs, total = await get_platform_cost_logs(
@@ -72,6 +81,9 @@ async def get_cost_logs(
user_id=user_id,
page=page,
page_size=page_size,
+ model=model,
+ block_name=block_name,
+ tracking_type=tracking_type,
)
total_pages = (total + page_size - 1) // page_size
return PlatformCostLogsResponse(
@@ -102,6 +114,9 @@ async def export_cost_logs(
end: datetime | None = Query(None),
provider: str | None = Query(None),
user_id: str | None = Query(None),
+ model: str | None = Query(None),
+ block_name: str | None = Query(None),
+ tracking_type: str | None = Query(None),
):
logger.info("Admin %s exporting platform cost logs", admin_user_id)
logs, truncated = await get_platform_cost_logs_for_export(
@@ -109,6 +124,9 @@ async def export_cost_logs(
end=end,
provider=provider,
user_id=user_id,
+ model=model,
+ block_name=block_name,
+ tracking_type=tracking_type,
)
return PlatformCostExportResponse(
logs=logs,
diff --git a/autogpt_platform/backend/backend/data/platform_cost.py b/autogpt_platform/backend/backend/data/platform_cost.py
index f45e5301eb..b44bb37910 100644
--- a/autogpt_platform/backend/backend/data/platform_cost.py
+++ b/autogpt_platform/backend/backend/data/platform_cost.py
@@ -175,6 +175,9 @@ def _build_where(
provider: str | None,
user_id: str | None,
table_alias: str = "",
+ model: str | None = None,
+ block_name: str | None = None,
+ tracking_type: str | None = None,
) -> tuple[str, list[Any]]:
prefix = f"{table_alias}." if table_alias else ""
clauses: list[str] = []
@@ -199,6 +202,18 @@ def _build_where(
clauses.append(f'{prefix}"userId" = ${idx}')
params.append(user_id)
idx += 1
+ if model:
+ clauses.append(f'{prefix}"model" = ${idx}')
+ params.append(model)
+ idx += 1
+ if block_name:
+ clauses.append(f'LOWER({prefix}"blockName") = LOWER(${idx})')
+ params.append(block_name)
+ idx += 1
+ if tracking_type:
+ clauses.append(f'{prefix}"trackingType" = ${idx}')
+ params.append(tracking_type)
+ idx += 1
return (" AND ".join(clauses) if clauses else "TRUE", params)
@@ -209,6 +224,9 @@ async def get_platform_cost_dashboard(
end: datetime | None = None,
provider: str | None = None,
user_id: str | None = None,
+ model: str | None = None,
+ block_name: str | None = None,
+ tracking_type: str | None = None,
) -> PlatformCostDashboard:
"""Aggregate platform cost logs for the admin dashboard.
@@ -223,7 +241,9 @@ async def get_platform_cost_dashboard(
"""
if start is None:
start = datetime.now(timezone.utc) - timedelta(days=DEFAULT_DASHBOARD_DAYS)
- where_p, params_p = _build_where(start, end, provider, user_id, "p")
+ where_p, params_p = _build_where(
+ start, end, provider, user_id, "p", model, block_name, tracking_type
+ )
by_provider_rows, by_user_rows, total_user_rows, total_agg_rows = (
await asyncio.gather(
@@ -339,10 +359,15 @@ async def get_platform_cost_logs(
user_id: str | None = None,
page: int = 1,
page_size: int = 50,
+ model: str | None = None,
+ block_name: str | None = None,
+ tracking_type: str | None = None,
) -> tuple[list[CostLogRow], int]:
if start is None:
start = datetime.now(tz=timezone.utc) - timedelta(days=DEFAULT_DASHBOARD_DAYS)
- where_sql, params = _build_where(start, end, provider, user_id, "p")
+ where_sql, params = _build_where(
+ start, end, provider, user_id, "p", model, block_name, tracking_type
+ )
offset = (page - 1) * page_size
limit_idx = len(params) + 1
@@ -421,6 +446,9 @@ async def get_platform_cost_logs_for_export(
end: datetime | None = None,
provider: str | None = None,
user_id: str | None = None,
+ model: str | None = None,
+ block_name: str | None = None,
+ tracking_type: str | None = None,
) -> tuple[list[CostLogRow], bool]:
"""Return all matching rows up to EXPORT_MAX_ROWS.
@@ -429,7 +457,9 @@ async def get_platform_cost_logs_for_export(
"""
if start is None:
start = datetime.now(tz=timezone.utc) - timedelta(days=DEFAULT_DASHBOARD_DAYS)
- where_sql, params = _build_where(start, end, provider, user_id, "p")
+ where_sql, params = _build_where(
+ start, end, provider, user_id, "p", model, block_name, tracking_type
+ )
limit_idx = len(params) + 1
rows = await query_raw_with_schema(
diff --git a/autogpt_platform/backend/backend/util/metrics.py b/autogpt_platform/backend/backend/util/metrics.py
index 30a979cffb..2a072b3135 100644
--- a/autogpt_platform/backend/backend/util/metrics.py
+++ b/autogpt_platform/backend/backend/util/metrics.py
@@ -4,11 +4,19 @@ from enum import Enum
import sentry_sdk
from pydantic import SecretStr
from sentry_sdk.integrations import DidNotEnable
-from sentry_sdk.integrations.anthropic import AnthropicIntegration
from sentry_sdk.integrations.asyncio import AsyncioIntegration
-from sentry_sdk.integrations.launchdarkly import LaunchDarklyIntegration
from sentry_sdk.integrations.logging import LoggingIntegration
+try:
+ from sentry_sdk.integrations.anthropic import AnthropicIntegration
+except ImportError:
+ AnthropicIntegration = None # type: ignore[assignment,misc]
+
+try:
+ from sentry_sdk.integrations.launchdarkly import LaunchDarklyIntegration
+except ImportError:
+ LaunchDarklyIntegration = None # type: ignore[assignment,misc]
+
from backend.util import feature_flag
from backend.util.settings import BehaveAs, Settings
@@ -131,25 +139,27 @@ def _before_send(event, hint):
def sentry_init():
sentry_dsn = settings.secrets.sentry_dsn
integrations = []
- if feature_flag.is_configured():
+ if feature_flag.is_configured() and LaunchDarklyIntegration is not None:
try:
integrations.append(LaunchDarklyIntegration(feature_flag.get_client()))
except DidNotEnable as e:
logger.error(f"Error enabling LaunchDarklyIntegration for Sentry: {e}")
+ optional_integrations = (
+ [AnthropicIntegration(include_prompts=False)]
+ if AnthropicIntegration is not None
+ else []
+ )
sentry_sdk.init(
dsn=sentry_dsn,
traces_sample_rate=1.0,
profiles_sample_rate=1.0,
environment=f"app:{settings.config.app_env.value}-behave:{settings.config.behave_as.value}",
- _experiments={"enable_logs": True},
before_send=_before_send,
integrations=[
AsyncioIntegration(),
- LoggingIntegration(sentry_logs_level=logging.INFO),
- AnthropicIntegration(
- include_prompts=False,
- ),
+ LoggingIntegration(),
]
+ + optional_integrations
+ integrations,
)
diff --git a/autogpt_platform/frontend/src/app/(platform)/admin/platform-costs/components/PlatformCostContent.tsx b/autogpt_platform/frontend/src/app/(platform)/admin/platform-costs/components/PlatformCostContent.tsx
index 81aa761b26..749a2136a3 100644
--- a/autogpt_platform/frontend/src/app/(platform)/admin/platform-costs/components/PlatformCostContent.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/admin/platform-costs/components/PlatformCostContent.tsx
@@ -15,6 +15,9 @@ interface Props {
end?: string;
provider?: string;
user_id?: string;
+ model?: string;
+ block_name?: string;
+ tracking_type?: string;
page?: string;
tab?: string;
};
@@ -37,6 +40,12 @@ export function PlatformCostContent({ searchParams }: Props) {
setProviderInput,
userInput,
setUserInput,
+ modelInput,
+ setModelInput,
+ blockInput,
+ setBlockInput,
+ typeInput,
+ setTypeInput,
rateOverrides,
handleRateOverride,
updateUrl,
@@ -107,6 +116,54 @@ export function PlatformCostContent({ searchParams }: Props) {
onChange={(e) => setUserInput(e.target.value)}
/>
</div>
+ <div className="flex flex-col gap-1">
+ <label
+ htmlFor="model-filter"
+ className="text-sm text-muted-foreground"
+ >
+ Model
+ </label>
+ <input
+ id="model-filter"
+ type="text"
+ placeholder="e.g. gpt-4o"
+ className="rounded border px-3 py-1.5 text-sm"
+ value={modelInput}
+ onChange={(e) => setModelInput(e.target.value)}
+ />
+ </div>
+ <div className="flex flex-col gap-1">
+ <label
+ htmlFor="block-filter"
+ className="text-sm text-muted-foreground"
+ >
+ Block
+ </label>
+ <input
+ id="block-filter"
+ type="text"
+ placeholder="e.g. LLMBlock"
+ className="rounded border px-3 py-1.5 text-sm"
+ value={blockInput}
+ onChange={(e) => setBlockInput(e.target.value)}
+ />
+ </div>
+ <div className="flex flex-col gap-1">
+ <label
+ htmlFor="type-filter"
+ className="text-sm text-muted-foreground"
+ >
+ Type
+ </label>
+ <input
+ id="type-filter"
+ type="text"
+ placeholder="e.g. tokens"
+ className="rounded border px-3 py-1.5 text-sm"
+ value={typeInput}
+ onChange={(e) => setTypeInput(e.target.value)}
+ />
+ </div>
<button
onClick={handleFilter}
className="rounded bg-primary px-4 py-1.5 text-sm text-primary-foreground hover:bg-primary/90"
@@ -119,11 +176,17 @@ export function PlatformCostContent({ searchParams }: Props) {
setEndInput("");
setProviderInput("");
setUserInput("");
+ setModelInput("");
+ setBlockInput("");
+ setTypeInput("");
updateUrl({
start: "",
end: "",
provider: "",
user_id: "",
+ model: "",
+ block_name: "",
+ tracking_type: "",
page: "1",
});
}}
diff --git a/autogpt_platform/frontend/src/app/(platform)/admin/platform-costs/components/usePlatformCostContent.ts b/autogpt_platform/frontend/src/app/(platform)/admin/platform-costs/components/usePlatformCostContent.ts
index 99074c5d35..7b3f92036d 100644
--- a/autogpt_platform/frontend/src/app/(platform)/admin/platform-costs/components/usePlatformCostContent.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/admin/platform-costs/components/usePlatformCostContent.ts
@@ -20,6 +20,9 @@ interface InitialSearchParams {
end?: string;
provider?: string;
user_id?: string;
+ model?: string;
+ block_name?: string;
+ tracking_type?: string;
page?: string;
tab?: string;
}
@@ -35,11 +38,19 @@ export function usePlatformCostContent(searchParams: InitialSearchParams) {
const providerFilter =
urlParams.get("provider") || searchParams.provider || "";
const userFilter = urlParams.get("user_id") || searchParams.user_id || "";
+ const modelFilter = urlParams.get("model") || searchParams.model || "";
+ const blockFilter =
+ urlParams.get("block_name") || searchParams.block_name || "";
+ const typeFilter =
+ urlParams.get("tracking_type") || searchParams.tracking_type || "";
const [startInput, setStartInput] = useState(toLocalInput(startDate));
const [endInput, setEndInput] = useState(toLocalInput(endDate));
const [providerInput, setProviderInput] = useState(providerFilter);
const [userInput, setUserInput] = useState(userFilter);
+ const [modelInput, setModelInput] = useState(modelFilter);
+ const [blockInput, setBlockInput] = useState(blockFilter);
+ const [typeInput, setTypeInput] = useState(typeFilter);
const [rateOverrides, setRateOverrides] = useState<Record<string, number>>(
{},
);
@@ -53,6 +64,9 @@ export function usePlatformCostContent(searchParams: InitialSearchParams) {
end: (endDate || undefined) as unknown as Date | undefined,
provider: providerFilter || undefined,
user_id: userFilter || undefined,
+ model: modelFilter || undefined,
+ block_name: blockFilter || undefined,
+ tracking_type: typeFilter || undefined,
};
const {
@@ -98,6 +112,9 @@ export function usePlatformCostContent(searchParams: InitialSearchParams) {
end: toUtcIso(endInput),
provider: providerInput,
user_id: userInput,
+ model: modelInput,
+ block_name: blockInput,
+ tracking_type: typeInput,
page: "1",
});
}
@@ -162,6 +179,12 @@ export function usePlatformCostContent(searchParams: InitialSearchParams) {
setProviderInput,
userInput,
setUserInput,
+ modelInput,
+ setModelInput,
+ blockInput,
+ setBlockInput,
+ typeInput,
+ setTypeInput,
rateOverrides,
handleRateOverride,
updateUrl,
diff --git a/autogpt_platform/frontend/src/app/api/openapi.json b/autogpt_platform/frontend/src/app/api/openapi.json
index a36b1e1502..004fd513fb 100644
--- a/autogpt_platform/frontend/src/app/api/openapi.json
+++ b/autogpt_platform/frontend/src/app/api/openapi.json
@@ -55,6 +55,33 @@
"anyOf": [{ "type": "string" }, { "type": "null" }],
"title": "User Id"
}
+ },
+ {
+ "name": "model",
+ "in": "query",
+ "required": false,
+ "schema": {
+ "anyOf": [{ "type": "string" }, { "type": "null" }],
+ "title": "Model"
+ }
+ },
+ {
+ "name": "block_name",
+ "in": "query",
+ "required": false,
+ "schema": {
+ "anyOf": [{ "type": "string" }, { "type": "null" }],
+ "title": "Block Name"
+ }
+ },
+ {
+ "name": "tracking_type",
+ "in": "query",
+ "required": false,
+ "schema": {
+ "anyOf": [{ "type": "string" }, { "type": "null" }],
+ "title": "Tracking Type"
+ }
}
],
"responses": {
@@ -153,6 +180,33 @@
"default": 50,
"title": "Page Size"
}
+ },
+ {
+ "name": "model",
+ "in": "query",
+ "required": false,
+ "schema": {
+ "anyOf": [{ "type": "string" }, { "type": "null" }],
+ "title": "Model"
+ }
+ },
+ {
+ "name": "block_name",
+ "in": "query",
+ "required": false,
+ "schema": {
+ "anyOf": [{ "type": "string" }, { "type": "null" }],
+ "title": "Block Name"
+ }
+ },
+ {
+ "name": "tracking_type",
+ "in": "query",
+ "required": false,
+ "schema": {
+ "anyOf": [{ "type": "string" }, { "type": "null" }],
+ "title": "Tracking Type"
+ }
}
],
"responses": {
@@ -180,6 +234,108 @@
}
}
},
+ "/api/admin/platform-costs/logs/export": {
+ "get": {
+ "tags": ["v2", "admin", "platform-cost", "admin"],
+ "summary": "Export Platform Cost Logs",
+ "operationId": "getV2Export platform cost logs",
+ "security": [{ "HTTPBearerJWT": [] }],
+ "parameters": [
+ {
+ "name": "start",
+ "in": "query",
+ "required": false,
+ "schema": {
+ "anyOf": [
+ { "type": "string", "format": "date-time" },
+ { "type": "null" }
+ ],
+ "title": "Start"
+ }
+ },
+ {
+ "name": "end",
+ "in": "query",
+ "required": false,
+ "schema": {
+ "anyOf": [
+ { "type": "string", "format": "date-time" },
+ { "type": "null" }
+ ],
+ "title": "End"
+ }
+ },
+ {
+ "name": "provider",
+ "in": "query",
+ "required": false,
+ "schema": {
+ "anyOf": [{ "type": "string" }, { "type": "null" }],
+ "title": "Provider"
+ }
+ },
+ {
+ "name": "user_id",
+ "in": "query",
+ "required": false,
+ "schema": {
+ "anyOf": [{ "type": "string" }, { "type": "null" }],
+ "title": "User Id"
+ }
+ },
+ {
+ "name": "model",
+ "in": "query",
+ "required": false,
+ "schema": {
+ "anyOf": [{ "type": "string" }, { "type": "null" }],
+ "title": "Model"
+ }
+ },
+ {
+ "name": "block_name",
+ "in": "query",
+ "required": false,
+ "schema": {
+ "anyOf": [{ "type": "string" }, { "type": "null" }],
+ "title": "Block Name"
+ }
+ },
+ {
+ "name": "tracking_type",
+ "in": "query",
+ "required": false,
+ "schema": {
+ "anyOf": [{ "type": "string" }, { "type": "null" }],
+ "title": "Tracking Type"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Successful Response",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/PlatformCostExportResponse"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/HTTP401NotAuthenticatedError"
+ },
+ "422": {
+ "description": "Validation Error",
+ "content": {
+ "application/json": {
+ "schema": { "$ref": "#/components/schemas/HTTPValidationError" }
+ }
+ }
+ }
+ }
+ }
+ },
"/api/analytics/log_raw_analytics": {
"post": {
"tags": ["analytics"],
@@ -7473,81 +7629,6 @@
}
}
}
- },
- "/api/admin/platform-costs/logs/export": {
- "get": {
- "tags": ["v2", "admin", "platform-cost", "admin"],
- "summary": "Export Platform Cost Logs",
- "operationId": "getV2Export platform cost logs",
- "security": [{ "HTTPBearerJWT": [] }],
- "parameters": [
- {
- "name": "start",
- "in": "query",
- "required": false,
- "schema": {
- "anyOf": [
- { "type": "string", "format": "date-time" },
- { "type": "null" }
- ],
- "title": "Start"
- }
- },
- {
- "name": "end",
- "in": "query",
- "required": false,
- "schema": {
- "anyOf": [
- { "type": "string", "format": "date-time" },
- { "type": "null" }
- ],
- "title": "End"
- }
- },
- {
- "name": "provider",
- "in": "query",
- "required": false,
- "schema": {
- "anyOf": [{ "type": "string" }, { "type": "null" }],
- "title": "Provider"
- }
- },
- {
- "name": "user_id",
- "in": "query",
- "required": false,
- "schema": {
- "anyOf": [{ "type": "string" }, { "type": "null" }],
- "title": "User Id"
- }
- }
- ],
- "responses": {
- "200": {
- "description": "Successful Response",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/PlatformCostExportResponse"
- }
- }
- }
- },
- "401": {
- "$ref": "#/components/responses/HTTP401NotAuthenticatedError"
- },
- "422": {
- "description": "Validation Error",
- "content": {
- "application/json": {
- "schema": { "$ref": "#/components/schemas/HTTPValidationError" }
- }
- }
- }
- }
- }
}
},
"components": {
@@ -9023,14 +9104,6 @@
"anyOf": [{ "type": "integer" }, { "type": "null" }],
"title": "Output Tokens"
},
- "cache_read_tokens": {
- "anyOf": [{ "type": "integer" }, { "type": "null" }],
- "title": "Cache Read Tokens"
- },
- "cache_creation_tokens": {
- "anyOf": [{ "type": "integer" }, { "type": "null" }],
- "title": "Cache Creation Tokens"
- },
"duration": {
"anyOf": [{ "type": "number" }, { "type": "null" }],
"title": "Duration"
@@ -9038,6 +9111,14 @@
"model": {
"anyOf": [{ "type": "string" }, { "type": "null" }],
"title": "Model"
+ },
+ "cache_read_tokens": {
+ "anyOf": [{ "type": "integer" }, { "type": "null" }],
+ "title": "Cache Read Tokens"
+ },
+ "cache_creation_tokens": {
+ "anyOf": [{ "type": "integer" }, { "type": "null" }],
+ "title": "Cache Creation Tokens"
}
},
"type": "object",
@@ -9293,7 +9374,14 @@
},
"CreditTransactionType": {
"type": "string",
- "enum": ["TOP_UP", "USAGE", "GRANT", "REFUND", "CARD_CHECK"],
+ "enum": [
+ "TOP_UP",
+ "USAGE",
+ "GRANT",
+ "REFUND",
+ "CARD_CHECK",
+ "SUBSCRIPTION"
+ ],
"title": "CreditTransactionType"
},
"DeleteFileResponse": {
@@ -12004,6 +12092,20 @@
],
"title": "PlatformCostDashboard"
},
+ "PlatformCostExportResponse": {
+ "properties": {
+ "logs": {
+ "items": { "$ref": "#/components/schemas/CostLogRow" },
+ "type": "array",
+ "title": "Logs"
+ },
+ "total_rows": { "type": "integer", "title": "Total Rows" },
+ "truncated": { "type": "boolean", "title": "Truncated" }
+ },
+ "type": "object",
+ "required": ["logs", "total_rows", "truncated"],
+ "title": "PlatformCostExportResponse"
+ },
"PlatformCostLogsResponse": {
"properties": {
"logs": {
@@ -15724,9 +15826,7 @@
"title": "Location"
},
"msg": { "type": "string", "title": "Message" },
- "type": { "type": "string", "title": "Error Type" },
- "input": { "title": "Input" },
- "ctx": { "type": "object", "title": "Context" }
+ "type": { "type": "string", "title": "Error Type" }
},
"type": "object",
"required": ["loc", "msg", "type"],
@@ -15829,20 +15929,6 @@
"expires_in_hours"
],
"title": "UploadFileResponse"
- },
- "PlatformCostExportResponse": {
- "properties": {
- "logs": {
- "items": { "$ref": "#/components/schemas/CostLogRow" },
- "type": "array",
- "title": "Logs"
- },
- "total_rows": { "type": "integer", "title": "Total Rows" },
- "truncated": { "type": "boolean", "title": "Truncated" }
- },
- "type": "object",
- "required": ["logs", "total_rows", "truncated"],
- "title": "PlatformCostExportResponse"
}
},
"securitySchemes": {