Skip to content

feat(economy): enterprise-aware mode (Bedrock/Vertex/OTEL) with USD-saved estimate#6

Closed
jhonatanjunio wants to merge 1 commit into
mainfrom
feat/p2-enterprise-mode
Closed

feat(economy): enterprise-aware mode (Bedrock/Vertex/OTEL) with USD-saved estimate#6
jhonatanjunio wants to merge 1 commit into
mainfrom
feat/p2-enterprise-mode

Conversation

@jhonatanjunio

Copy link
Copy Markdown
Owner

Closes #5

Summary

On Anthropic's usage-based enterprise plans there is no included token allowance — every token is billed at API rates and an admin-set spend cap pauses the workspace when hit (requires a manual refill ticket). This PR makes that economics visible inside squeez.

What changed

  • New module src/economy/enterprise.rs — env-var detection (Bedrock, Vertex, OTEL) + USD-savings estimator at Anthropic's public Sonnet 4.6 and Opus 4.7 rates. Zero new deps, no network calls.
  • Wrap header gains [squeez: enterprise=<slug>] when a transport is detected.
  • Init banner prints an enterprise hint, including USD saved in the prior session when available.
  • New MCP tool squeez_enterprise_savings returns mode + saved tokens + USD at both Sonnet and Opus rates — finance dashboards and the agent itself can quote a number.

How detection works

Env var Mode
CLAUDE_CODE_USE_BEDROCK=1 or AWS_BEDROCK_REGION bedrock
CLAUDE_CODE_USE_VERTEX=1 or ANTHROPIC_VERTEX_PROJECT_ID vertex
OTEL_EXPORTER_OTLP_ENDPOINT / OTEL_METRIC_EXPORT_INTERVAL / CLAUDE_CODE_ENABLE_TELEMETRY=1 otel
nothing none (no banner, no tag)

Precedence: Bedrock > Vertex > OTEL.

Verification

$ CLAUDE_CODE_USE_BEDROCK=1 \
  echo '{"jsonrpc":"2.0","id":1,"method":"tools/call",\
"params":{"name":"squeez_enterprise_savings","arguments":{}}}' \
  | ./target/release/squeez.exe mcp
{"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"{
  \"enterprise_mode\":\"bedrock\",
  \"is_enterprise\":true,
  \"tokens_saved_session\":2,
  \"usd_saved_sonnet46\":0.000006,
  \"usd_saved_opus47\":0.000010
}"}]}}

Tests

11 new unit tests:

  • 6 detection paths (Bedrock via flag, Bedrock via region var, Vertex via flag, Vertex via project ID, OTEL via endpoint, empty env)
  • Precedence (bedrock_beats_otel_when_both_set)
  • Truthy/falsy parsing (falsy_use_flag_is_not_enterprise)
  • Pricing math against published rates
  • Header tag rendering (empty when not enterprise)
  • Init banner rendering with/without prior savings

Full lib suite: 170/170 passing (159 prior + 11 new).

Design choices

  • No network calls — detection is env-var only, and we never read credentials.
  • Conservative pricing — Sonnet rate by default. Enterprise contracts often have negotiated discounts, so our number is at worst slightly overstated for fully discounted contracts and at best a fair on-demand-parity floor for everyone else.
  • Out of scope: enforcing or reporting to OTEL collectors (would couple us to a transport), per-key spend caps (those live on Anthropic's side).

…+ USD savings

Adds `economy::enterprise` which detects whether the host is wired to an
enterprise-cost transport (AWS Bedrock, Google Vertex, or an OTEL metrics
exporter) and exposes a small USD-savings estimator at Anthropic's public
input rates (Sonnet 4.6 $3/MTok, Opus 4.7 $5/MTok).

Three surfaces now expose the signal:
- Wrap header gains `[squeez: enterprise=<slug>]` whenever a transport is
  detected, so users see in real time that their saved tokens convert to
  workspace USD rather than to subscription credits.
- Init banner prints an enterprise hint, including USD saved in the prior
  session when available.
- New MCP tool `squeez_enterprise_savings` returns mode + saved-tokens +
  USD estimates at both Sonnet and Opus rates, so finance dashboards and
  agents can quote a number.

Detection is env-var only, no network or credential access. Defaults are
conservative — Sonnet rate, no overstating value.

Closes claudioemmanuel#129

Signed-off-by: Jhonatan Junio <jhonatanjuniocp@gmail.com>
@jhonatanjunio jhonatanjunio force-pushed the feat/p2-enterprise-mode branch from ac329b5 to 259ecb8 Compare May 18, 2026 17:11
@jhonatanjunio

Copy link
Copy Markdown
Owner Author

Superseded by upstream PR — moved to claudioemmanuel/squeez. See README of this fork for the upstream link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P2: Enterprise-aware mode — detect Bedrock/Vertex/OTEL + hBcsaved estimate

1 participant