Track OCI spend with the Usage API and set up budget alerts.
Use when monitoring Oracle Cloud costs, creating budgets, analyzing spend by compartment or service, or optimizing Universal Credits consumption.
Trigger with "oraclecloud cost", "oci budget", "oci usage api", "oci spending", "oracle cloud cost tuning".
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Une commande directe contourne le prompt de vérification. Examinez la source avant de l'exécuter.
Track OCI spend with the Usage API and set up budget alerts.
Use when monitoring Oracle Cloud costs, creating budgets, analyzing spend by compartment or service, or optimizing Universal Credits consumption.
Trigger with "oraclecloud cost", "oci budget", "oci usage api", "oci spending", "oracle cloud cost tuning".
allowed-tools
Read, Write, Edit, Bash(pip:*), Grep
version
1.7.0
license
MIT
author
Jeremy Longshore <jeremy@intentsolutions.io>
tags
["saas","oraclecloud","oci"]
compatibility
Designed for Claude Code
Oracle Cloud Cost Tuning
Overview
Track OCI spending programmatically using the Usage API and set up budget alerts before Universal Credits run out unexpectedly. OCI pricing varies by shape, region, and commitment level, and the Cost Analysis tool in the Console is buried and confusing. This skill uses the Usage API to query spend by compartment, service, and shape, creates budgets with alert rules, and covers optimization strategies including Always Free tier resources, preemptible instances, and reserved capacity.
Purpose: Get visibility into OCI spending through code, set proactive budget alerts, and identify cost optimization opportunities.
Prerequisites
OCI tenancy with an API signing key in ~/.oci/config
Python 3.8+ with pip install oci
Tenancy OCID (root compartment) for tenancy-wide cost queries
IAM policy granting read usage-reports in the tenancy
Notification topic OCID for budget alert delivery (see oraclecloud-observability)
Instructions
Step 1: Query Usage with the Usage API
The Usage API returns cost and usage data broken down by configurable dimensions:
import oci
from datetime import datetime, timedelta
config = oci.config.from_file("~/.oci/config")
usage_api = oci.usage_api.UsageapiClient(config)
# Query last 30 days of spend by service
response = usage_api.request_summarized_usages(
oci.usage_api.models.RequestSummarizedUsagesDetails(
tenant_id=config["tenancy"],
time_usage_started=(datetime.utcnow() - timedelta(days=30)).isoformat() + "Z",
time_usage_ended=datetime.utcnow().isoformat() + "Z",
granularity="DAILY",
query_type="COST",
group_by=["service"]
)
)
total_cost = 0.0for item in response.data.items:
cost = item.computed_amount or0
total_cost += cost
cost > :
()
()
if
0
print
f"{item.service}: ${cost:.2f} ({item.currency})"
print
f"\nTotal 30-day spend: ${total_cost:.2f}"
Step 2: Break Down Cost by Compartment and Shape
Identify which compartments and shapes are driving your bill:
After cost monitoring is in place, review oraclecloud-performance-tuning to right-size instances based on actual metrics, or see oraclecloud-observability to route budget alerts through the same notification topics as your infrastructure alarms.