Files · Anthropic LLM Observability for SMB AI Operations
64 (1 binary, 550.0 kB total)attempt 1
README.md·2175 B·markdown
markdown
# Anthropic LLM Observability for SMB AI Operations
> Drop-in OpenTelemetry instrumentation that gives SMBs real-time cost, latency, and error insights across all Anthropic API calls, plus pre-built dashboards for Langfuse and Phoenix.
A tutorialized reference solution from [reaatech.com](https://reaatech.com), demonstrating how to build production-grade AI observability with the `@reaatech/*` package family.
## Architecture
```
Anthropic SDK → AnthropicInstrumentation (OTel GenAI spans)
→ SpanBuilder (semconv attribute mapping)
→ SpanListener (budget enforcement via @reaatech/agent-budget-otel-bridge)
→ LangfuseExporter / PhoenixExporter (observability backend)
```
## Quick Start
```bash
pnpm install
cp .env.example .env
# Edit .env: set ANTHROPIC_API_KEY
pnpm dev # starts Express + Next.js
pnpm test # vitest run with coverage
```
## API Reference
| Route | Method | Description |
|-------|--------|-------------|
| `POST /api/chat` | POST | Send a chat message through instrumented Anthropic client |
| `POST /api/chat/stream` | POST | Streaming SSE chat response |
| `GET /health` | GET | Health check |
| `POST /webhooks/langfuse` | POST | Forward spans to Langfuse |
| `GET /api/budget/:tenantId` | GET | Get budget status for a tenant |
## Configuration
| Env Var | Required | Default | Description |
|---------|----------|---------|-------------|
| `ANTHROPIC_API_KEY` | Yes | - | Anthropic API key |
| `LANGFUSE_PUBLIC_KEY` | No* | - | Langfuse public key |
| `LANGFUSE_SECRET_KEY` | No* | - | Langfuse secret key |
| `PHOENIX_ENDPOINT` | No* | - | Phoenix endpoint URL |
| `EXPORTER_BACKEND` | No | `langfuse` | Active exporter (`langfuse` or `phoenix`) |
| `DEFAULT_DAILY_BUDGET` | No | `10.0` | Default daily spend cap in USD |
| `TENANT_BUDGETS` | No | - | Per-tenant budget overrides as JSON |
| `PORT` | No | `3000` | Express server port |
\* Required when EXPORTER_BACKEND matches the exporter.
## Testing
```bash
pnpm test # vitest with coverage
pnpm typecheck # TypeScript type checking
pnpm lint # ESLint
```
## License
MIT — see [LICENSE](./LICENSE).