Skip to main content
Glama

get_cost_usage_summary

Retrieve cost and usage summaries for Oracle Cloud tenancies by specifying date ranges and granularity to analyze spending across services and compartments.

Instructions

Get cost and usage summary for a tenancy. Args: tenant_id: OCID of the tenancy time_usage_started: Start time in ISO format (YYYY-MM-DD) time_usage_ended: End time in ISO format (YYYY-MM-DD) granularity: Granularity of the data (DAILY or MONTHLY), defaults to DAILY Returns: List of cost and usage summaries with amounts, services, and compartments

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tenant_idYes
time_usage_startedYes
time_usage_endedYes
granularityNoDAILY

Implementation Reference

  • Core handler function that queries the OCI Usage API for cost and usage summaries over a time period, aggregates results, and returns formatted list of summaries.
    def get_cost_usage_summary(usage_api_client: oci.usage_api.UsageapiClient, tenant_id: str, time_usage_started: str, time_usage_ended: str, granularity: str = "DAILY") -> List[Dict[str, Any]]: """ Get cost and usage summary for a tenancy. Args: usage_api_client: OCI UsageApi client tenant_id: OCID of the tenancy time_usage_started: Start time in ISO format (YYYY-MM-DD) time_usage_ended: End time in ISO format (YYYY-MM-DD) granularity: Granularity of the data (DAILY, MONTHLY) Returns: List of cost and usage summaries """ try: request_summarized_usages_details = oci.usage_api.models.RequestSummarizedUsagesDetails( tenant_id=tenant_id, time_usage_started=time_usage_started, time_usage_ended=time_usage_ended, granularity=granularity, is_aggregate_by_time=True ) usage_response = oci.pagination.list_call_get_all_results( usage_api_client.request_summarized_usages, request_summarized_usages_details=request_summarized_usages_details ) summaries = [] for item in usage_response.data.items: summaries.append({ "time_usage_started": str(item.time_usage_started), "time_usage_ended": str(item.time_usage_ended), "computed_amount": item.computed_amount, "computed_quantity": item.computed_quantity, "currency": item.currency, "service": item.service, "resource_name": item.resource_name, "compartment_name": item.compartment_name, "compartment_id": item.compartment_id, "unit": item.unit, }) logger.info(f"Retrieved {len(summaries)} usage summaries for tenancy {tenant_id}") return summaries except Exception as e: logger.exception(f"Error getting cost usage summary: {e}") raise
  • MCP server tool registration for 'get_cost_usage_summary'. Wraps the core handler with common error handling, logging, and profile management, and registers it with the FastMCP server.
    @mcp.tool(name="get_cost_usage_summary") @mcp_tool_wrapper( start_msg="Getting cost and usage summary...", error_prefix="Error getting cost usage summary" ) async def mcp_get_cost_usage_summary(ctx: Context, tenant_id: str, time_usage_started: str, time_usage_ended: str, granularity: str = "DAILY") -> List[Dict[str, Any]]: """ Get cost and usage summary for a tenancy. Args: tenant_id: OCID of the tenancy time_usage_started: Start time in ISO format (YYYY-MM-DD) time_usage_ended: End time in ISO format (YYYY-MM-DD) granularity: Granularity of the data (DAILY or MONTHLY), defaults to DAILY Returns: List of cost and usage summaries with amounts, services, and compartments """ return get_cost_usage_summary(oci_clients["usage_api"], tenant_id, time_usage_started, time_usage_ended, granularity)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jopsis/mcp-server-oci'

If you have feedback or need assistance with the MCP directory API, please join our Discord server