<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Violeta Fragosa</title>
    <description>The latest articles on DEV Community by Violeta Fragosa (@violetafragosa).</description>
    <link>https://dev.to/violetafragosa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4060783%2Fa1819d2c-d1f0-4237-8bff-e6930c848c94.png</url>
      <title>DEV Community: Violeta Fragosa</title>
      <link>https://dev.to/violetafragosa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/violetafragosa"/>
    <language>en</language>
    <item>
      <title>Building an AI Agent That Actually Monitors Your APIs</title>
      <dc:creator>Violeta Fragosa</dc:creator>
      <pubDate>Thu, 06 Aug 2026 08:38:22 +0000</pubDate>
      <link>https://dev.to/violetafragosa/building-an-ai-agent-that-actually-monitors-your-apis-156b</link>
      <guid>https://dev.to/violetafragosa/building-an-ai-agent-that-actually-monitors-your-apis-156b</guid>
      <description>&lt;h2&gt;
  
  
  The $50,000 Mistake I Almost Made
&lt;/h2&gt;

&lt;p&gt;Last November, I deployed a new API endpoint for our SaaS platform. Everything looked fine in staging. The integration tests passed. The load tests showed acceptable response times. I pushed to production on a Friday afternoon (yes, I know).&lt;/p&gt;

&lt;p&gt;By Monday morning, we had burned through 47% of our Anthropic API quota. Not from legitimate traffic — from a retry loop in our webhook handler that nobody caught because our monitoring alerts were configured for HTTP errors, not for API consumption patterns or logical errors in flow control.&lt;/p&gt;

&lt;p&gt;The fix took 30 seconds once we found it. But the detection took three days. And by then, we'd spent $2,847 on unnecessary API calls, dangerously close to hitting the hard limit that would have taken down our entire service.&lt;/p&gt;

&lt;p&gt;That's when I realized: &lt;strong&gt;monitoring HTTP status codes isn't enough. You need an agent that understands your API's behavior, tracks consumption patterns, detects anomalies, and can even draft incident reports or documentation updates based on what it observes.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So I built one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Traditional API Monitoring Fails
&lt;/h2&gt;

&lt;p&gt;Before we dive into the build, let's talk about why Datadog, New Relic, and CloudWatch aren't enough for modern API-driven systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Traditional monitoring is reactive.&lt;/strong&gt; It tells you when something is already broken:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;500 errors? Alert fires.&lt;/li&gt;
&lt;li&gt;Response time over 2 seconds? Alert fires.&lt;/li&gt;
&lt;li&gt;Error rate above 5%? Alert fires.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;But what about:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A slow increase in API consumption that indicates a loop or inefficiency?&lt;/li&gt;
&lt;li&gt;A new endpoint being called in an unusual pattern suggesting misintegration?&lt;/li&gt;
&lt;li&gt;Changes in request payloads that could indicate a breaking change you introduced?&lt;/li&gt;
&lt;li&gt;Deprecation warnings from third-party APIs you depend on?&lt;/li&gt;
&lt;li&gt;Opportunities to optimize based on actual usage patterns?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are behavioral signals that require reasoning, not just threshold checking. And that's where an autonomous agent comes in.&lt;/p&gt;

&lt;h2&gt;
  
  
  What We're Building: The API Sentinel Agent
&lt;/h2&gt;

&lt;p&gt;Here's what this agent does:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Continuous Monitoring&lt;/strong&gt;: Polls your API logs, cloud metrics, and third-party API status pages&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pattern Recognition&lt;/strong&gt;: Uses LLM reasoning to detect anomalies, not just threshold violations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consumption Tracking&lt;/strong&gt;: Tracks API quota usage across multiple providers (OpenAI, Anthropic, Google, etc.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Documentation Sync&lt;/strong&gt;: Automatically detects when your API behavior diverges from your docs and drafts updates&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Incident Reporting&lt;/strong&gt;: When something goes wrong, generates a detailed incident report with timeline, impact analysis, and suggested fixes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost Optimization&lt;/strong&gt;: Identifies opportunities to reduce API costs based on actual usage patterns&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Unlike my previous post about Hermes Agent for tech radar, this one focuses on &lt;strong&gt;operational monitoring&lt;/strong&gt; rather than information gathering. But the underlying principles are the same: memory, reasoning, scheduling, and action.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Tech Stack
&lt;/h2&gt;

&lt;p&gt;Here's what I used to build this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Core Agent Framework&lt;/strong&gt;: Hermes Agent (same as before, but different skills)&lt;br&gt;
&lt;strong&gt;Log Ingestion&lt;/strong&gt;: Fluent Bit → CloudWatch Logs → Agent API polling&lt;br&gt;
&lt;strong&gt;Metrics&lt;/strong&gt;: Prometheus + custom exporters for API provider quotas&lt;br&gt;
&lt;strong&gt;LLM&lt;/strong&gt;: Claude 3.5 Sonnet (best for reasoning about patterns and anomalies)&lt;br&gt;
&lt;strong&gt;Storage&lt;/strong&gt;: SQLite for agent memory + PostgreSQL for historical metrics&lt;br&gt;
&lt;strong&gt;Notifications&lt;/strong&gt;: Telegram for critical alerts, weekly digest via email&lt;/p&gt;

&lt;p&gt;The key architectural decision was making the agent &lt;strong&gt;pull-based&lt;/strong&gt; rather than push-based. Instead of sending every log line to the LLM (expensive and slow), the agent periodically queries aggregated metrics and recent error logs, then reasons about whether patterns are worth investigating.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: Setting Up the Base Agent
&lt;/h2&gt;

&lt;p&gt;If you haven't already installed Hermes Agent, start here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Install Hermes Agent&lt;/span&gt;
curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.sh | bash

&lt;span class="c"&gt;# Run the interactive setup&lt;/span&gt;
hermes setup &lt;span class="nt"&gt;--portal&lt;/span&gt;

&lt;span class="c"&gt;# This will:&lt;/span&gt;
&lt;span class="c"&gt;# - Configure your preferred LLM provider (OpenAI, Anthropic, local, etc.)&lt;/span&gt;
&lt;span class="c"&gt;# - Set up the SQLite memory database&lt;/span&gt;
&lt;span class="c"&gt;# - Create your first agent session&lt;/span&gt;
&lt;span class="c"&gt;# - Configure optional integrations (Telegram, Slack, etc.)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;During setup, choose these options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;LLM Provider&lt;/strong&gt;: Anthropic (Claude 3.5 Sonnet has the best reasoning for pattern detection)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memory&lt;/strong&gt;: Enhanced (you want long-term pattern recognition)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cron&lt;/strong&gt;: Enabled (we'll schedule monitoring runs)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once installed, verify it's working:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hermes chat

&lt;span class="c"&gt;# In the chat session, try:&lt;/span&gt;
&lt;span class="c"&gt;# "Remember that I'm building an API monitoring agent"&lt;/span&gt;
&lt;span class="c"&gt;# "What's the current date and time?"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The agent should respond naturally and confirm it saved the memory about your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Creating the API Monitoring Skill
&lt;/h2&gt;

&lt;p&gt;Skills are reusable procedures that teach the agent how to perform specific workflows. We're going to create a skill called &lt;code&gt;api-sentinel&lt;/code&gt; that contains the monitoring logic.&lt;/p&gt;

&lt;p&gt;Create a new file at &lt;code&gt;~/.hermes/skills/api-sentinel.md&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; ~/.hermes/skills
&lt;span class="nb"&gt;touch&lt;/span&gt; ~/.hermes/skills/api-sentinel.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's the skill definition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# API Sentinel Skill&lt;/span&gt;

&lt;span class="gu"&gt;## Purpose&lt;/span&gt;
Monitor API health, consumption, and behavior patterns to detect issues before they become critical.

&lt;span class="gu"&gt;## Workflow&lt;/span&gt;

&lt;span class="gu"&gt;### 1. Data Collection Phase&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Fetch last 1 hour of error logs from CloudWatch
&lt;span class="p"&gt;-&lt;/span&gt; Query Prometheus for API latency metrics (p50, p95, p99)
&lt;span class="p"&gt;-&lt;/span&gt; Check API quota usage for all providers:
&lt;span class="p"&gt;  -&lt;/span&gt; OpenAI API (via usage API)
&lt;span class="p"&gt;  -&lt;/span&gt; Anthropic API (via usage API)
&lt;span class="p"&gt;  -&lt;/span&gt; AWS API Gateway (via CloudWatch metrics)
&lt;span class="p"&gt;-&lt;/span&gt; Fetch recent deployment events from CI/CD system

&lt;span class="gu"&gt;### 2. Pattern Analysis Phase&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Compare current metrics against 7-day baseline
&lt;span class="p"&gt;-&lt;/span&gt; Identify anomalies:
&lt;span class="p"&gt;  -&lt;/span&gt; Error rate increase &amp;gt;20%
&lt;span class="p"&gt;  -&lt;/span&gt; Latency increase &amp;gt;50%
&lt;span class="p"&gt;  -&lt;/span&gt; API consumption increase &amp;gt;30% without traffic increase
&lt;span class="p"&gt;  -&lt;/span&gt; New error types not seen in past 7 days
&lt;span class="p"&gt;-&lt;/span&gt; Correlate anomalies with recent deployments

&lt;span class="gu"&gt;### 3. Investigation Phase&lt;/span&gt;
For each detected anomaly:
&lt;span class="p"&gt;-&lt;/span&gt; Retrieve sample error logs
&lt;span class="p"&gt;-&lt;/span&gt; Analyze error messages for root cause indicators
&lt;span class="p"&gt;-&lt;/span&gt; Check if similar issues occurred historically
&lt;span class="p"&gt;-&lt;/span&gt; Assess impact severity (critical/warning/info)

&lt;span class="gu"&gt;### 4. Reporting Phase&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Generate incident report if critical issues found
&lt;span class="p"&gt;-&lt;/span&gt; Update findings document with observations
&lt;span class="p"&gt;-&lt;/span&gt; Send Telegram notification for critical/warning issues
&lt;span class="p"&gt;-&lt;/span&gt; Update Prometheus metrics with analysis results

&lt;span class="gu"&gt;### 5. Documentation Sync Phase&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Compare current API behavior against OpenAPI spec
&lt;span class="p"&gt;-&lt;/span&gt; Identify divergences (new fields, changed types, deprecated endpoints)
&lt;span class="p"&gt;-&lt;/span&gt; Draft documentation update if needed

&lt;span class="gu"&gt;## Memory Keys&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="sb"&gt;`api_baseline_metrics`&lt;/span&gt;: 7-day rolling averages
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="sb"&gt;`known_error_patterns`&lt;/span&gt;: Previously seen and resolved errors
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="sb"&gt;`quota_thresholds`&lt;/span&gt;: Alert thresholds for each API provider
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="sb"&gt;`last_check_timestamp`&lt;/span&gt;: Track monitoring intervals

&lt;span class="gu"&gt;## Commands Available&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="sb"&gt;`check_cloudwatch_logs --hours 1`&lt;/span&gt;: Fetch recent logs
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="sb"&gt;`query_prometheus --metric api_latency_p95`&lt;/span&gt;: Query metrics
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="sb"&gt;`check_openai_usage`&lt;/span&gt;: Get OpenAI quota usage
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="sb"&gt;`check_anthropic_usage`&lt;/span&gt;: Get Anthropic quota usage
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="sb"&gt;`send_telegram_alert --severity critical --message "..."`&lt;/span&gt;: Send alert
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save this file, then register the skill:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hermes skill load api-sentinel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The agent can now execute this workflow on command or on schedule.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Setting Up Data Sources
&lt;/h2&gt;

&lt;p&gt;The agent needs access to your metrics and logs. Here's how to configure each integration:&lt;/p&gt;

&lt;h3&gt;
  
  
  CloudWatch Logs Integration
&lt;/h3&gt;

&lt;p&gt;Create a script at &lt;code&gt;~/.hermes/tools/check_cloudwatch_logs.sh&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="c"&gt;# Fetch CloudWatch logs for the past N hours&lt;/span&gt;

&lt;span class="nv"&gt;HOURS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;START_TIME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$((&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;date&lt;/span&gt; +%s&lt;span class="si"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;$HOURS&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="m"&gt;3600&lt;/span&gt;&lt;span class="k"&gt;))&lt;/span&gt;000
&lt;span class="nv"&gt;LOG_GROUP&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/aws/lambda/api-handler"&lt;/span&gt;

aws logs filter-log-events &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--log-group-name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$LOG_GROUP&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--start-time&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$START_TIME&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--filter-pattern&lt;/span&gt; &lt;span class="s2"&gt;"[ERROR]"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--max-items&lt;/span&gt; 100 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--output&lt;/span&gt; json | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.events[].message'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make it executable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x ~/.hermes/tools/check_cloudwatch_logs.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Prometheus Metrics Integration
&lt;/h3&gt;

&lt;p&gt;Create &lt;code&gt;~/.hermes/tools/query_prometheus.sh&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="c"&gt;# Query Prometheus for specific metrics&lt;/span&gt;

&lt;span class="nv"&gt;METRIC&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="nv"&gt;http_request_duration_seconds&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;PROMETHEUS_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"http://localhost:9090"&lt;/span&gt;

curl &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PROMETHEUS_URL&lt;/span&gt;&lt;span class="s2"&gt;/api/v1/query?query=&lt;/span&gt;&lt;span class="nv"&gt;$METRIC&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.data.result'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  API Usage Tracking
&lt;/h3&gt;

&lt;p&gt;For OpenAI usage tracking, create &lt;code&gt;~/.hermes/tools/check_openai_usage.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;#!/usr/bin/env python3
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timedelta&lt;/span&gt;

&lt;span class="n"&gt;API_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;OPENAI_API_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;ORG_ID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;OPENAI_ORG_ID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;check_usage&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Check OpenAI API usage for the current billing period&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Authorization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bearer &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;API_KEY&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;OpenAI-Organization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ORG_ID&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;# Get usage data
&lt;/span&gt;    &lt;span class="n"&gt;end_date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;start_date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;end_date&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nf"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;days&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://api.openai.com/v1/usage&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;start_date&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;start_date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;%Y-%m-%d&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;end_date&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;end_date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;%Y-%m-%d&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;total_tokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;n_context_tokens_total&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;day&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;data&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[]))&lt;/span&gt;
        &lt;span class="n"&gt;total_cost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;n_context_tokens_total&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.00002&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;day&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;data&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[]))&lt;/span&gt;

        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;OpenAI Usage (30 days):&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;  Total tokens: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;total_tokens&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;  Estimated cost: $&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;total_cost&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;  Daily average: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;total_tokens&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; tokens&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;total_tokens&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;total_tokens&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;total_cost&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;total_cost&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;daily_average&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;total_tokens&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Error: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; - &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;check_usage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make it executable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x ~/.hermes/tools/check_openai_usage.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: Configuring the Monitoring Schedule
&lt;/h2&gt;

&lt;p&gt;Now let's set up the agent to run every 6 hours:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hermes cron add &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s2"&gt;"api-sentinel-monitor"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--schedule&lt;/span&gt; &lt;span class="s2"&gt;"0 */6 * * *"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--prompt&lt;/span&gt; &lt;span class="s2"&gt;"Execute the api-sentinel skill to monitor API health and usage patterns. Focus on detecting anomalies and cost optimization opportunities."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can verify the cron job was added:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hermes cron list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To test the monitoring run manually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hermes chat &lt;span class="nt"&gt;--prompt&lt;/span&gt; &lt;span class="s2"&gt;"Execute the api-sentinel skill and provide a detailed report"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 5: Setting Up Alerts and Notifications
&lt;/h2&gt;

&lt;p&gt;The agent can send alerts to multiple channels. Let's configure Telegram for critical issues:&lt;/p&gt;

&lt;h3&gt;
  
  
  Telegram Setup
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Create a new bot via &lt;a href="https://t.me/botfather" rel="noopener noreferrer"&gt;@BotFather&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Get your bot token&lt;/li&gt;
&lt;li&gt;Get your chat ID (send a message to your bot, then visit &lt;code&gt;https://api.telegram.org/bot&amp;lt;TOKEN&amp;gt;/getUpdates&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Configure Hermes with your Telegram credentials:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hermes config &lt;span class="nb"&gt;set &lt;/span&gt;telegram.bot_token &lt;span class="s2"&gt;"YOUR_BOT_TOKEN"&lt;/span&gt;
hermes config &lt;span class="nb"&gt;set &lt;/span&gt;telegram.chat_id &lt;span class="s2"&gt;"YOUR_CHAT_ID"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a notification skill at &lt;code&gt;~/.hermes/skills/send-alert.md&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Send Alert Skill&lt;/span&gt;

&lt;span class="gu"&gt;## Purpose&lt;/span&gt;
Send formatted alerts to Telegram for API issues

&lt;span class="gu"&gt;## Workflow&lt;/span&gt;
&lt;span class="p"&gt;1.&lt;/span&gt; Assess severity level (critical/warning/info)
&lt;span class="p"&gt;2.&lt;/span&gt; Format message with:
&lt;span class="p"&gt;   -&lt;/span&gt; Timestamp
&lt;span class="p"&gt;   -&lt;/span&gt; Severity emoji (🔴/🟡/🔵)
&lt;span class="p"&gt;   -&lt;/span&gt; Issue description
&lt;span class="p"&gt;   -&lt;/span&gt; Impact assessment
&lt;span class="p"&gt;   -&lt;/span&gt; Suggested action
&lt;span class="p"&gt;3.&lt;/span&gt; Send via Telegram API
&lt;span class="p"&gt;4.&lt;/span&gt; Log alert to memory for future reference

&lt;span class="gu"&gt;## Example Output&lt;/span&gt;
🔴 &lt;span class="gs"&gt;**CRITICAL: High API Consumption Detected**&lt;/span&gt;
Timestamp: 2026-08-06 14:23:15 UTC

OpenAI API usage is 340% above baseline.
Affected endpoint: /api/webhooks/process

Impact: $47/hour burn rate (normal: $12/hour)

Suggested Actions:
&lt;span class="p"&gt;-&lt;/span&gt; Check for retry loops in webhook handler
&lt;span class="p"&gt;-&lt;/span&gt; Review recent deployments
&lt;span class="p"&gt;-&lt;/span&gt; Consider rate limiting

Investigation: [View Logs]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 6: Real-World Usage Example
&lt;/h2&gt;

&lt;p&gt;Let me show you what the agent actually does in practice. Here's a real monitoring run output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;hermes chat &lt;span class="nt"&gt;--prompt&lt;/span&gt; &lt;span class="s2"&gt;"Run api-sentinel monitoring"&lt;/span&gt;
&lt;span class="go"&gt;
🤖 Hermes Agent: Executing API Sentinel monitoring...

📊 Data Collection (14:30:15 UTC)
- CloudWatch logs: 23 error events in past 1 hour
- API latency (p95): 245ms (baseline: 180ms) ⚠️ +36%
- OpenAI usage: 2.3M tokens today (baseline: 1.8M) ⚠️ +28%
- Anthropic usage: Within normal range
- Recent deployments: 1 deployment 2 hours ago

🔍 Pattern Analysis
Anomaly detected: Latency spike correlates with deployment

Investigating error logs...
Found 18 instances of: "RetryableError: Anthropic API rate limit"

This suggests the retry logic in src/api/ai_handler.py is not backing off correctly.

🎯 Root Cause Analysis
Issue: Exponential backoff is configured but not being applied
Location: src/api/ai_handler.py:87
Fix: The retry decorator is using linear backoff instead of exponential

Impact Assessment: WARNING
- Current: ~18 failed requests/hour
- If unaddressed: Could escalate to service degradation
- Cost impact: Minimal (failed requests don't consume quota)

📝 Recommended Actions
1. Update retry configuration to use exponential backoff
2. Add circuit breaker for Anthropic API calls
3. Update monitoring to alert on retry rate

Would you like me to:
- Draft a GitHub issue for this?
- Send a Telegram alert?
- Update the API documentation?
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The agent didn't just tell me there was an error — it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Correlated the timing with a deployment&lt;/li&gt;
&lt;li&gt;Analyzed the error pattern&lt;/li&gt;
&lt;li&gt;Identified the specific code location&lt;/li&gt;
&lt;li&gt;Assessed business impact&lt;/li&gt;
&lt;li&gt;Suggested concrete fixes&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 7: Advanced Features
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Cost Optimization Analysis
&lt;/h3&gt;

&lt;p&gt;Add a monthly cost review cron job:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hermes cron add &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s2"&gt;"monthly-cost-review"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--schedule&lt;/span&gt; &lt;span class="s2"&gt;"0 9 1 * *"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--prompt&lt;/span&gt; &lt;span class="s2"&gt;"Analyze API usage patterns from the past month. Identify opportunities to reduce costs through caching, batching, or provider optimization. Generate a detailed report with projected savings."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This agent will analyze your API usage and suggest optimizations like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Caching frequently requested data&lt;/li&gt;
&lt;li&gt;Batching small requests&lt;/li&gt;
&lt;li&gt;Switching to cheaper models for simple tasks&lt;/li&gt;
&lt;li&gt;Identifying redundant API calls&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Documentation Drift Detection
&lt;/h3&gt;

&lt;p&gt;Create a skill that compares your OpenAPI spec against actual API behavior:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Documentation Drift Detection Skill&lt;/span&gt;

&lt;span class="gu"&gt;## Purpose&lt;/span&gt;
Ensure API documentation stays in sync with actual implementation

&lt;span class="gu"&gt;## Workflow&lt;/span&gt;
&lt;span class="p"&gt;1.&lt;/span&gt; Parse OpenAPI specification
&lt;span class="p"&gt;2.&lt;/span&gt; Analyze actual API request/response logs
&lt;span class="p"&gt;3.&lt;/span&gt; Detect mismatches:
&lt;span class="p"&gt;   -&lt;/span&gt; New fields not in spec
&lt;span class="p"&gt;   -&lt;/span&gt; Deprecated endpoints still in spec
&lt;span class="p"&gt;   -&lt;/span&gt; Changed response types
&lt;span class="p"&gt;   -&lt;/span&gt; New error codes
&lt;span class="p"&gt;4.&lt;/span&gt; Draft documentation update PR
&lt;span class="p"&gt;5.&lt;/span&gt; Notify team via Slack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Anomaly Learning
&lt;/h3&gt;

&lt;p&gt;The agent improves over time by learning from false positives:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hermes chat
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"The latency spike at 3am every day is expected - it's our nightly batch job. Don't alert on it."&lt;/span&gt;

🤖 Understood. I&lt;span class="s1"&gt;'ve updated my memory:
- Ignore latency spikes between 3:00-3:30am
- Associated with: nightly batch processing
- Pattern: expected operational behavior
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Troubleshooting Common Issues
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Issue 1: Agent Not Detecting Anomalies
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Symptom&lt;/strong&gt;: Agent runs but reports "no issues found" even when there are obvious problems&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Diagnosis&lt;/strong&gt;: The baseline metrics might not be properly calibrated&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Reset baseline and recalibrate&lt;/span&gt;
hermes memory delete api_baseline_metrics
hermes chat &lt;span class="nt"&gt;--prompt&lt;/span&gt; &lt;span class="s2"&gt;"Analyze the past 7 days of API metrics to establish a new baseline"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Issue 2: Too Many False Positive Alerts
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Symptom&lt;/strong&gt;: Getting alerts for normal traffic variations&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix&lt;/strong&gt;: Adjust sensitivity thresholds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hermes config &lt;span class="nb"&gt;set &lt;/span&gt;api_sentinel.latency_threshold 50  &lt;span class="c"&gt;# Increase from 30%&lt;/span&gt;
hermes config &lt;span class="nb"&gt;set &lt;/span&gt;api_sentinel.error_threshold 25    &lt;span class="c"&gt;# Increase from 20%&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Issue 3: Missing API Provider Credentials
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Symptom&lt;/strong&gt;: "Cannot fetch usage data" errors&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix&lt;/strong&gt;: Ensure environment variables are set:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;OPENAI_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"sk-..."&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;ANTHROPIC_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"sk-ant-..."&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;AWS_ACCESS_KEY_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;AWS_SECRET_ACCESS_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Cost Breakdown: Running This Agent
&lt;/h2&gt;

&lt;p&gt;Let me be transparent about what this costs to run:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Infrastructure&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hermes Agent: Free (self-hosted)&lt;/li&gt;
&lt;li&gt;SQLite storage: Free&lt;/li&gt;
&lt;li&gt;Prometheus: Free (self-hosted)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;LLM Costs&lt;/strong&gt; (Claude 3.5 Sonnet):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Monitoring run: ~5K input tokens, ~2K output tokens&lt;/li&gt;
&lt;li&gt;Cost per run: ~$0.08&lt;/li&gt;
&lt;li&gt;4 runs/day: ~$9.60/month&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Data Transfer&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CloudWatch API calls: Minimal (~$2/month)&lt;/li&gt;
&lt;li&gt;Metrics queries: Free (self-hosted Prometheus)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Total: ~$12/month&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For reference, that one incident I mentioned at the start cost us $2,847. This agent would have caught it within 6 hours and cost me $0.08.&lt;/p&gt;

&lt;p&gt;ROI is pretty clear.&lt;/p&gt;

&lt;h2&gt;
  
  
  Beyond Monitoring: What Else Can This Do?
&lt;/h2&gt;

&lt;p&gt;Once you have an agent watching your APIs, you can extend it to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Automatic Incident Response&lt;/strong&gt;: Not just detect but also remediate (e.g., scale up resources, enable circuit breakers)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security Monitoring&lt;/strong&gt;: Detect unusual access patterns that might indicate an attack&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compliance Reporting&lt;/strong&gt;: Generate audit reports for SOC2, ISO 27001, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance Optimization&lt;/strong&gt;: Suggest code changes based on profiling data&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User Behavior Analysis&lt;/strong&gt;: Understand how your API is actually being used vs. how you designed it&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The key is that you have a reasoning engine that can look at data holistically, not just individual metrics in isolation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion: Monitoring That Thinks
&lt;/h2&gt;

&lt;p&gt;Traditional monitoring tells you &lt;strong&gt;what&lt;/strong&gt; happened. This agent tells you &lt;strong&gt;why&lt;/strong&gt; it happened and &lt;strong&gt;what to do about it&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It's the difference between:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"Error rate increased to 5%" &lt;/li&gt;
&lt;li&gt;vs. "Error rate increased to 5% because the deployment 2 hours ago introduced a retry loop in the webhook handler at line 87. This is costing $35/hour in unnecessary API calls. Fix: change the retry strategy from linear to exponential backoff. Here's the code change: [...]"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I've been running this for three months now. It's caught:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;7 potential incidents before they impacted users&lt;/li&gt;
&lt;li&gt;$3,200 in unnecessary API spending&lt;/li&gt;
&lt;li&gt;4 documentation drift issues&lt;/li&gt;
&lt;li&gt;2 security concerns (unusual API access patterns)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;More importantly, I sleep better knowing that if something goes wrong at 3am, I'll get an intelligent alert that tells me exactly what's wrong and what to do — not just a cryptic "Error rate high" page.&lt;/p&gt;

&lt;p&gt;The code is open source. The agent framework is free. The LLM costs are negligible compared to what you'll save in incident prevention.&lt;/p&gt;

&lt;p&gt;Build it. Run it. Improve it. And let me know what patterns your agent discovers.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>hermes</category>
      <category>agents</category>
    </item>
    <item>
      <title>Stop hitting Codex rate limits mid-task</title>
      <dc:creator>Violeta Fragosa</dc:creator>
      <pubDate>Mon, 03 Aug 2026 15:31:48 +0000</pubDate>
      <link>https://dev.to/violetafragosa/stop-hitting-codex-rate-limits-mid-task-284h</link>
      <guid>https://dev.to/violetafragosa/stop-hitting-codex-rate-limits-mid-task-284h</guid>
      <description>&lt;p&gt;Hit Codex's five-hour limit again last week, right in the middle of debugging a state management issue. Agent had already burned through half the context window figuring out the problem, and then — &lt;code&gt;429&lt;/code&gt;. Session gone. Had to wait two hours to pick it back up.&lt;/p&gt;

&lt;p&gt;That sucks. And it's happened enough times that I finally did something about it. Built a local proxy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/cherrylfrei-max/codex-conduit" rel="noopener noreferrer"&gt;Codex Conduit&lt;/a&gt; sits between your Codex client and whichever accounts or API providers you use. It shows quota status, lets you switch routes mid-session without losing context, and auto-fails over to another account when one hits the five-hour limit or throws a rate error.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftqd11rg2bwqzybm7cepd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftqd11rg2bwqzybm7cepd.png" alt="Codex Conduit dashboard" width="800" height="524"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What it does
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Manage ChatGPT subscription accounts, OpenAI API keys, and third-party providers in one place&lt;/li&gt;
&lt;li&gt;See five-hour and weekly quota usage (where the upstream reports it), plus account health&lt;/li&gt;
&lt;li&gt;Switch between accounts without restarting Codex — keeps your session and context intact&lt;/li&gt;
&lt;li&gt;Auto-switch to another account when one hits the five-hour limit, so your task keeps running&lt;/li&gt;
&lt;li&gt;Control which routes participate in auto-selection (free, relay, paid, third-party)&lt;/li&gt;
&lt;li&gt;Backs up your original &lt;code&gt;~/.codex/config.toml&lt;/code&gt; and restores it when you disable the proxy&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;Grab the installer from the &lt;a href="https://github.com/cherrylfrei-max/codex-conduit/releases" rel="noopener noreferrer"&gt;releases page&lt;/a&gt;. macOS and Windows builds are up. Quit any running Codex CLI or Codex App processes before enabling the proxy — saves you from weird config states.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Add accounts:&lt;/strong&gt; Click &lt;strong&gt;+ Sign In&lt;/strong&gt; to go through OpenAI's OAuth flow in your browser. For third-party providers that expose &lt;code&gt;/v1/responses&lt;/code&gt; or &lt;code&gt;/chat/completions&lt;/code&gt;, use &lt;strong&gt;+ Add Third-Party Provider&lt;/strong&gt; and paste your API key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check status:&lt;/strong&gt; The Accounts page shows which route is active, remaining quota or balance, health state, and when it was last refreshed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fri99ctq8h4xa09ebpqni.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fri99ctq8h4xa09ebpqni.png" alt="Codex Conduit accounts" width="800" height="529"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enable the proxy:&lt;/strong&gt; Flip &lt;strong&gt;Local Proxy&lt;/strong&gt; on in the Dashboard. The app backs up your Codex config, writes the proxy settings, and starts routing. Restart your Codex client and you're set. Turn it off later and it restores everything.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Routing policy:&lt;/strong&gt; Under &lt;strong&gt;Settings &amp;gt; Background Services&lt;/strong&gt;, pick which routes can auto-switch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzl9tswrpjd7f50dgybgs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzl9tswrpjd7f50dgybgs.png" alt="Codex Conduit routing settings" width="799" height="525"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My setup: third-party routes stay out of auto-selection (I want to explicitly choose when I'm paying per token), subscription accounts are available as fallback when a paid route dies, and free-tier accounts stay out of rotation.&lt;/p&gt;

&lt;h2&gt;
  
  
  How failover works
&lt;/h2&gt;

&lt;p&gt;The gateway sits between your Codex client and the upstream:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Codex CLI / Codex App / IDE
               |
               v
      Codex Conduit (local)
               |
    healthy account or provider
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When it sees &lt;code&gt;401&lt;/code&gt;, &lt;code&gt;429&lt;/code&gt;, or a quota-exhausted response, it picks the next healthy route that matches your policy. You still hit provider limits — this just saves you from manually reconfiguring when one runs dry. The dashboard shows which route is active, so you know what you're using.&lt;/p&gt;

&lt;h2&gt;
  
  
  Does this actually help?
&lt;/h2&gt;

&lt;p&gt;The five-hour window is still there on individual subscription routes. Can't get around that.&lt;/p&gt;

&lt;p&gt;But I'm wasting less time checking quota before I start, switching accounts mid-session, editing configs, restarting Codex... you know the drill. The dashboard gives me a quick answer to "which account should I use right now" instead of trial and error.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it / break it
&lt;/h2&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/cherrylfrei-max/codex-conduit" rel="noopener noreferrer"&gt;https://github.com/cherrylfrei-max/codex-conduit&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bugs, feature requests, PRs — all welcome. If something's broken or unclear, open an issue and I'll take a look.&lt;/p&gt;

</description>
      <category>codex</category>
      <category>opensource</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
