Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

tensorcost

Latest version: v1.8.1

Overview

Last scanned
25 Nov 2026
Published
25 Nov 2026
PyPI package Publisher: tensorcpst-admin
0 Stars
0 Forks
9 Versions
705 Downloads
Python Repo language

Scan summary

tensorcost was last scanned on 25 Nov 2026 at version 1.8.1. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 9 versions; the latest 2 were published within 2 days (24 and 25 Nov 2026).
  • Findings: No rules fired in version 1.8.1.
  • Downloads: 705 downloads.

Versions

9 versions published
Versions and the rules that fired in each
VersionPublishedStatus
1.8.1 LATEST 25 Nov 2026 No rules fired
1.8.0 24 Nov 2026 No rules fired
1.7.0 14 Nov 2026 No rules fired
1.6.0 12 Nov 2026 Not shown
1.5.1 12 Nov 2026 Not shown

No rules fired in 1.8.1

Findings

Findings for v1.8.1. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 1.8.1; other versions have their own rules, not their own score.

README

The publisher’s own README, as collected from the registry.

TensorCost SDK for Python

PyPI Python license

Wrap your OpenAI, Anthropic, AWS Bedrock or Google Vertex AI client in one line, and every call shows up in TensorCost: what it cost, which model, team, customer and agent it was for. Your code keeps calling the provider exactly as before.

When you want more than visibility, the same wrapper can enforce budgets and policies before a call goes out, and route calls to a cheaper model through the TensorCost proxy.

  • One line. wrap(client) and nothing else changes.
  • Never in your way. Telemetry is fire-and-forget. If TensorCost is slow or down, your call still goes through.
  • Metadata only. Prompts and completions never leave your process.

Install

pip install tensorcost

Python 3.9 or later. The only dependency is httpx.

Quick start

import os
from openai import OpenAI
from tensorcost import wrap

client = wrap(
    OpenAI(),
    api_key=os.environ["TENSORCOST_API_KEY"],
    tenant_id=os.environ["TENSORCOST_TENANT_ID"],
)

reply = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello"}],
)

Anthropic works the same way:

from anthropic import Anthropic
from tensorcost import wrap

client = wrap(Anthropic())  # reads TENSORCOST_API_KEY and TENSORCOST_TENANT_ID

client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=256,
    messages=[{"role": "user", "content": "Hello"}],
)
Your keys

In the TensorCost console:

  • Connect › API keys creates the SDK key (TENSORCOST_API_KEY).
  • Connect › SDK setup shows your tenant id (TENSORCOST_TENANT_ID).

The SDK trades the key for a short-lived token and refreshes it on its own.

Configuration

Arguments passed to wrap() win over environment variables, which win over defaults.

Environment variable What it's for Required
TENSORCOST_API_KEY Your SDK key Yes
TENSORCOST_TENANT_ID Your tenant id Yes
TENSORCOST_BASE_URL TensorCost API (default https://api.tensorcost.com) No
TENSORCOST_PROXY_URL TensorCost proxy, for the steer and route layers For steer / route
TENSORCOST_ENVIRONMENT Environment tag on every call (production, staging, …) No
TENSORCOST_APPLICATION Application the calls belong to No
TENSORCOST_TAGS Comma-separated tags No
TENSORCOST_TEAM_ID Team the calls belong to No
TENSORCOST_AGENT_ID / TENSORCOST_WORKFLOW_ID Default agent and run No
TENSORCOST_AUTO_WORKFLOW_ID Set to 1 to give each wrapped client with an agent a fresh run id No
TENSORCOST_CUSTOMER / TENSORCOST_FEATURE Default customer and feature, for chargeback No
TENSORCOST_FLUSH_ON_EXIT Set to 0 to skip the drain at interpreter exit No
TENSORCOST_SPOOL_DIR Directory for the disk spool (off when unset) No
client = wrap(
    OpenAI(),
    application="customer-support",
    tags=["tier:enterprise"],
)

Without a tenant id, observe warns once and sends nothing; govern and above raise MissingConfigError when you call wrap().

Control layers

How much TensorCost may do with a call is a ladder:

Layer Path What happens
off Direct Nothing. The client comes back unwrapped.
observe Direct Telemetry only. The default.
govern Direct A metadata-only check before each call. Budgets, approved models, guardrails and compliance profiles can refuse it.
steer Via proxy The call goes through the TensorCost proxy, which can apply policy to it.
route Via proxy The proxy can send the call to another model under your routing policies.

The layer you set is a ceiling, not a switch. TensorCost uses the lower of your max_layer and the layer published in the console (Authority › Routing), so you can turn control up or down without a deploy.

client = wrap(
    OpenAI(),
    max_layer="route",
    proxy_url=os.environ["TENSORCOST_PROXY_URL"],
)

steer and route need a proxy_url; wrap() raises MissingConfigError without one. govern doesn't.

A sensible rollout is observe, then govern, then route, raising the console's layer only once each step looks right. A call at route only moves to another model when a routing policy for it is switched on; until then it goes to your provider unchanged, and the decision is recorded.

The SDK caches the console's layer for 30 seconds and never waits more than 250 ms for it. If TensorCost can't be reached for five minutes, it settles at govern: it keeps checking, and never raises itself to route on its own.

Compliance profiles

When your workspace assigns compliance profiles (GDPR, HIPAA, PCI-DSS, the EU AI Act, data residency), the SDK enforces them at govern and above. Pattern detectors run inside your process before the provider is called, so a matched secret never leaves it and never reaches TensorCost. Set team_id to apply a team's profile.

Attribution

Every call can say who and what it was for. Set defaults on wrap(), or per call with with_meta():

client = wrap(OpenAI(), agent_id="support-bot")

client.with_meta(workflow_id="ticket-48291", customer="acme", feature="ticket-triage").chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Summarize this ticket"}],
)
Field Shows up as
application, tags Spend by application and tag
agent_id, workflow_id Agent runs and run caps
customer, feature Cost per customer and feature

with_meta() works on OpenAI and Anthropic clients. Bedrock and Vertex take the defaults set on wrap().

Reliability

If TensorCost is down, your call still reaches the provider. The SDK goes around TensorCost only when the call provably never reached the provider: TensorCost couldn't be reached at all (connection refused, DNS, a TLS handshake failure), the circuit is open, or TensorCost answered before forwarding (a 429 or 402 with no refusal in it, the proxy's or the gateway's own 503), and only while fail_open_enabled is on (the default). Anything TensorCost actually answers as a decision reaches your code as an error, and is never retried or sent around it.

A failure after the call may have reached the provider is never sent again, through TensorCost or around it: a timeout once the request was sent, a dropped connection, a 5xx the provider sent (marked x-tc-error-origin: provider, raised as the provider SDK's own error), any other 5xx TensorCost can't prove it sent before forwarding, and anything with x-should-retry: false. Those reach your code as the error, with may_have_reached_provider set to true, because resending could bill the call twice. Through 1.7.0 the SDK retried those and then called the provider directly, so one call could run up to six times.

  • Retries. Only calls that provably never reached the provider are retried, with jittered backoff, honouring Retry-After on a 429.
  • Timeouts. The check before a call is capped at 500 ms. Through the proxy, a call waits up to timeout_s (60 s).
  • Circuit breaker. After three proxy failures in a row, calls go straight to the provider. Every 5 s one call probes the proxy with a single attempt, never retried: if it fails, that call goes to the provider at once and the circuit stays open for another 5 s. Once probes succeed calls go through the proxy again. A call never retries through a circuit that opened while it was running.
  • Streaming. At steer and route, stream=True calls go straight to the provider (with fail_open_enabled=False they raise MissingConfigError instead).
from tensorcost import RetryConfig, wrap

client = wrap(
    OpenAI(),
    max_layer="route",
    proxy_url=os.environ["TENSORCOST_PROXY_URL"],
    retry=RetryConfig(max_attempts=5, base_delay_ms=500.0, max_delay_ms=30_000.0),
    timeout_s=60.0,
    on_lifecycle_event=lambda e: print(e.kind, e.model),
)

Where calls must never go around TensorCost (a proxy inside your VPC, say), set fail_open_enabled=False and proxy failures raise instead.

Warnings go to the tensorcost logger.

Observation delivery

Observations are sent from background threads and never slow your call down. One that fails to send (a network error, a timeout, a 5xx, a 408 or a 429) waits in memory and is retried with backoff: 1 s, doubling to 60 s, with jitter, and Retry-After honoured on a 429. While TensorCost is unreachable only one request at a time probes it. Each retry resends the same body with the same correlation_id, and ingestion dedupes on it, so nothing is counted twice. A 4xx other than 408 and 429 (a 400, 401, 403 or 422, say) is not retried, since the same body would get the same answer: it is counted in observation_stats().rejected and logged once, then at most once a minute. An observation is given up on after an hour. When delivery recovers after an outage the SDK logs it once, and observation_stats().delivered_after_retry counts what was held back and then delivered.

Up to max_buffered_observations (10 000) or max_buffered_bytes (32 MiB) wait at once. Past that the oldest goes, with at most one warning a minute, and observation_stats().dropped counts it.

At interpreter exit an atexit hook spends up to 2 s sending what is queued. atexit runs on a normal exit and under servers that turn SIGTERM into a clean shutdown (gunicorn, uvicorn); a bare SIGTERM or SIGKILL skips it. Set flush_on_exit=False to turn the hook off.

With spool_dir set, observations that would otherwise be lost (the buffer was full, or they were still undelivered at exit) are written there as JSONL and sent on the next start. The directory is capped at spool_max_bytes (64 MiB) by deleting the oldest files. Processes can share one directory, and the format is the same as the Node SDK's.

from tensorcost import observation_stats, wrap

client = wrap(OpenAI(), spool_dir="/var/lib/myapp/tensorcost")
# later, from a health check
stats = observation_stats()
print(stats.buffered, stats.dropped, stats.spooled)

Errors

Every error is a TensorCostError. Refusals all extend TensorCostRefusedError, so one except covers them, including any refusal this version doesn't know by name:

Error When
TensorCostBudgetHardCapError A budget's hard cap was reached. retryable is true when its spend isn't counted yet.
TensorCostPeriodBudgetExceededError A daily or monthly cap was reached (scope, period, cap_cents, spent_cents).
TensorCostRunBudgetExceededError A run reached its cap.
TensorCostRunStoppedError Someone stopped the run.
TensorCostModelGovernanceDeniedError The model isn't approved for this team.
TensorCostGuardrailHardStopError A guardrail stopped the call.
TensorCostComplianceDeniedError A compliance profile refused the call.
from tensorcost import TensorCostRefusedError

try:
    client.chat.completions.create(model="gpt-4o", messages=messages)
except TensorCostRefusedError as err:
    print("TensorCost refused the call:", err.code, err.reason)
    raise

A provider's own error (a bad request, say) reaches you as the provider SDK's error, as it would without TensorCost. Configuration problems raise MissingConfigError when you call wrap().

Serverless

prewarm() at import time fetches the token and the console's layer before the first request arrives, so the first call doesn't wait for them. A Lambda is frozen between invocations rather than exited, so the atexit drain never runs there: before the handler returns, call flush_observations(), which sends anything queued or waiting to retry. If TensorCost is unreachable it gives up after one attempt instead of using the whole timeout, and what is left goes out on a later invocation. It returns how many observations are still waiting (0 when everything landed).

from tensorcost import flush_observations, prewarm, wrap

prewarm(max_layer="route")
client = wrap(OpenAI(), max_layer="route", proxy_url=os.environ["TENSORCOST_PROXY_URL"])

def handler(event, context):
    reply = client.chat.completions.create(model="gpt-4o-mini", messages=event["messages"])
    flush_observations(timeout_s=3.0)
    return reply.choices[0].message.content

Supported providers

Provider Client Layers Calls
OpenAI openai 1.x observe to route Chat, completions, embeddings, responses, streamed or not
Azure OpenAI openai (AzureOpenAI) observe to route As OpenAI
Anthropic anthropic observe, govern Messages, streamed or not
AWS Bedrock boto3 (bedrock-runtime) observe invoke_model, converse, and their streams
Google Vertex AI google-genai (vertexai=True) observe generate_content, streamed or not

Bedrock and Vertex sign requests inside their own SDKs, so they can't go through the proxy: steer and route raise MissingConfigError, and govern is accepted but not enforced yet (the SDK warns once). Anthropic at steer or route runs at govern.

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • pypi-releases tensorcost

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Vulnerability Insights

OpenSSH Password Authentication Bypass on Alpine Linux (*sshole) – CVE-2026-123158

PHP2Shell, Day 5 93.6% of Measurable Instances Still Unpatched (1)
Vulnerability Insights

PHP2Shell, Day 5: The Panic Hasn’t Turned Into Patching

Copy of Template Design OX Blog (1)
Research

Thousands Of GitHub Accounts Hijacked With wfx-loot CI Secret Stealing Malware Via GitHub Actions & npm

Frame 2085668439 (1)
Group 1261154229