Developer tools
If you’re calling OpenAI, Anthropic, or Bedrock directly from your own code (as opposed to connecting your cloud account through the console), the SDKs are the fastest way to get that traffic showing up in TensorCost. Wrap your existing client in one line; nothing else about your code changes.Looking for the terminal tool that estimates prompt cost without any account or network access? That’s the CLI — a separate, simpler tool.
Node.js — @tensorcost/sdk
fetch).
@aws-sdk/client-bedrock-runtime is an optional peer dependency — install it only if you’re using Bedrock:
InvokeModelCommand and ConverseCommand report full token counts. InvokeModelWithResponseStreamCommand and ConverseStreamCommand currently report latency and success/error only — per-chunk token accounting for streaming Bedrock calls is on the roadmap.
Configuration
Or pass options explicitly:
wrap(client, { apiKey: "...", baseUrl: "..." }).
Applied mode (routing through TensorCost)
By default the SDK is observe-only — your call goes straight to the provider, and a fire-and-forget observation ships afterward. SettingappliedMode: true (plus a proxyUrl) instead routes OpenAI and Anthropic calls through TensorCost’s inference proxy, which can redirect a request to a different provider per your policy. Applied mode is not available for Bedrock — Bedrock’s request signing happens inside the AWS SDK before our wrapper can intercept it, so wrap(bedrockClient, { appliedMode: true }) throws immediately.
In applied mode you can also configure retries, timeouts, lifecycle hooks, and a fail-open circuit breaker (opens after 3 consecutive proxy failures, routes direct to the provider, closes again after 5 consecutive successful probes). See the package README on npm for the full option list and typed error classes.
What gets sent
Only metadata — provider, model, operation, timestamps, token counts, status, and a correlation ID. Prompt and completion content are never captured.Fail-open guarantee
If TensorCost is slow, down, or misconfigured, your underlying provider call still completes normally — the SDK logs a warning and moves on. The one exception is a missing API key, which throws atwrap() time rather than silently dropping every observation.
Python — tensorcost
httpx only.
Configuration
wrap() resolves config from, in order: explicit keyword arguments, then environment variables (TENSORCOST_API_KEY, TENSORCOST_BASE_URL, TENSORCOST_TENANT_ID, TENSORCOST_PROXY_URL), then defaults (base_url defaults to https://api.tensorcost.com). A missing API key raises MissingConfigError.
Applied mode
Same idea as the Node SDK:applied_mode=True plus proxy_url routes chat.completions / messages.create through the TensorCost inference proxy, which can redirect the call based on tenant policy. If the proxy call fails, the SDK falls back to the direct provider call and logs a warning rather than failing your request.
Currently supported (Python)
- OpenAI (
openai >= 1.0) —chat.completions.create,completions.create - Anthropic (
anthropic >= 0.20) —messages.create