Skip to main content
Loading navigation
Back to prompt library

Build a Hosted Claude Client-Side Latency and Budget Observability Engine — implementation

Linked challenge: Build a Hosted Claude Client-Side Latency and Budget Observability Engine

Prompt source

implementation67 lines11 sectionsNo variables1 code block
## Build
Track client-side HTTP request latencies and per-call token costs for hosted Claude API workloads. Flag budget pacing anomalies and latency threshold breaches for platform engineering oversight.

## User
AI Platform Reliability Engineer

## Workflow
1. Ingest normalized client request telemetry logs containing round-trip time and token usage.
2. Calculate token consumption costs against published tier pricing and verify budget burndown velocity.
3. Detect client-side p95 latency degradations and error bursts across caller application IDs.
4. Generate Claude-assisted platform incident briefings with recommended client retry pacing limits.

## Interface
Web dashboard displaying real-time token spend gauges, latency percentiles, and downloadable incident reviews.

## Data
Construct a synthetic log stream of 500 Anthropic API client responses with client timestamps and token counts.
Starter examples below are synthetic. They are not downloaded records.

## Source
[Anthropic Python SDK](https://raw.githubusercontent.com/anthropics/anthropic-sdk-python/main/README.md)
Utilize Anthropic Python SDK client invocation standards, message structures, and usage counter patterns.

## Tools
langfuse, anthropic, pydantic.
langfuse provides open tracing abstractions to capture client-side duration and token metrics cleanly.
Hosted Claude API accessed over HTTPS for log explanation and diagnostic report generation.

## Deliverables
Submit runnable source, pinned dependencies, setup commands, a working interface, example outputs, and a recorded end-to-end demo. Include tests and an action log.

## Acceptance
- Computes cumulative input and output token spend strictly from client usage metadata.
- Flags client application endpoints exceeding configured latency SLAs without assuming server internals.
- Synthesizes structured incident action items for client-side connection pool tuning.

## Starter Examples
```json
[
  {
    "input": {
      "app_id": "customer-support-bot",
      "requests": 150,
      "total_input_tokens": 120000,
      "total_output_tokens": 30000,
      "client_p95_ms": 4200,
      "daily_budget_usd": 50
    },
    "expected_output": {
      "calculated_spend_usd": 0.81,
      "budget_pacing": "healthy",
      "latency_sla_breach": true,
      "recommendation": "enable_streaming_or_reduce_max_tokens"
    }
  },
  {
    "input": {
      "app_id": "batch-document-indexer",
      "requests": 500,
      "total_input_tokens": 25000000,
      "total_output_tokens": 4000000,
      "client_p95_ms": 11500,
      "daily_budget_usd": 100
    },
    "expected_output": {
      "calculated_spend_usd": 135,
      "budget_pacing": "exceeded",
      "latency_sla_breach": true,
      "recommendation": "throttle_client_concurrency_apply_batch_api"
    }
  }
]
```

## Safety
Performs client-side telemetry observability only, making no assertions about proprietary model server hardware or internal routing.
Use mock external writes. Require human review before any real deployment.