Install
Get your keys
1
Mint an SDK key
In the console open Connect › SDK setup and choose Mint SDK key. The key is filled into the snippet on that page and shown once, so copy it then. In the form you pick the key’s environment, which starts on your production one. You need the workspace admin role. After you mint a key, the button is replaced by a note to copy it until your first call is counted. Then the key leaves the page and the button comes back. Mint more, and list or revoke them, on Connect › API keys.
2
Take your workspace id
The snippet on Connect › SDK setup already carries your workspace id (the SDK calls it the tenant id).
3
Set both in your environment
Wrap a client
- Node.js
- Python
observe warns once and sends nothing.
The default layer is observe: telemetry only. To refuse or reroute calls, read Control layers.
See the first call
Connect › SDK setup watches for your first call for five minutes after you open it. When one arrives it shows the call’s model, cost and how long ago it ran. If nothing arrives, the page says so and offers Check again. Check thatTENSORCOST_API_KEY, TENSORCOST_TENANT_ID and TENSORCOST_BASE_URL are set in the shell that runs your code, and that the key belongs to this workspace.
Configuration
Options passed towrap() win over environment variables, which win over defaults.
The Node.js SDK also reads
TENSORCOST_DEPLOYMENT and TENSORCOST_PROMPT_TEMPLATE_ID. The Python SDK reads TENSORCOST_AUTO_WORKFLOW_ID; set it to 1 to give each wrapped client with an agent a fresh run id. What each field does is in Attribution.
Supported providers
Only the calls the SDK wraps are observed; for example, Node.js observes OpenAI chat completions but not embeddings, while Python also covers embeddings and responses. Bedrock and Vertex sign requests inside their own SDKs, so they cannot go through the proxy. Anthropic at
steer or route runs at govern. The Node.js SDK also has wrapLangChain, wrapLlamaIndex, wrapCrewAI and wrapVercelAi.
What is sent
Metadata only: provider, model, operation, token counts, timings and status; the environment, application, tags, team, agent, run, customer and feature you set; and the provider account the call was billed under, read from the provider’s response. TensorCost uses that account to match each call with the provider’s own bill, so discounts and credits reach your cost figures. Your provider key is never sent.Full reference
Errors, retries, serverless helpers and every option are on the package pages. For the command line see CLI, and for what each layer may do to a call see Control layers.@tensorcost/sdk
Node.js reference on npm.
tensorcost
Python reference on PyPI.