Skip to main content

FluxCompute SDK

CI PyPI Python License: Apache 2.0

Route every query to the cheapest model that can answer it. FluxCompute classifies each request and dispatches it to the right tier, so simple questions stop costing frontier-model prices, and reports exactly what you saved on every call.

pip install fluxcompute
import asyncio
from fluxcompute import FluxClient


async def main():
    client = FluxClient(anthropic_key="sk-ant-...")

    response = await client.messages.create(
        model="auto",                                    # let FluxCompute decide
        messages=[{"role": "user", "content": "What is 2+2?"}],
    )

    print(response.text)                          # "4"
    print(response.fluxcompute.model_selected)    # claude-haiku-4-5
    print(response.fluxcompute.savings_usd)       # 0.0035

    await client.close()


asyncio.run(main())

Already using the Anthropic or OpenAI SDK? Swap the client and pass model="auto". The response object keeps the fields you already use, with routing and cost data added under response.fluxcompute.

How routing works

Each request gets a difficulty score from a heuristic classifier (prompt structure, reasoning markers, length, task type), which maps to a tier:

Score Tier Anthropic OpenAI
< 0.18 easy claude-haiku-4-5 gpt-4o-mini
0.180.45 medium claude-sonnet-4-6 gpt-4o
>= 0.45 hard claude-opus-4-8 o1

Savings come from the queries that get downgraded: against the default baseline, an easy-tier call costs 80% less and a medium-tier call 40% less. Hard queries route to the baseline model itself, so they save nothing by design: your overall reduction is therefore a function of how much of your traffic genuinely needs a frontier model. The examples measure this on a mixed workload rather than asserting a number.

Every response carries the score, the label, the model chosen, and the counterfactual cost against your baseline model, so the routing is auditable rather than a black box. Pin a specific model any time by passing it instead of "auto".

Multi-turn sessions get tier-aware context compression: pass a session_id and history is carried across turns and compressed when a session drops to a cheaper tier, so switching models mid-conversation doesn't re-bill the full transcript.

Execution graphs

Wrap work in a task() scope and the SDK records a DAG of everything that happened inside it: LLM calls and your own steps, auto-parented, with status, timings, tokens, cost, and a rules-based failure classification (context overflow, budget, tool error, stall, refusal).

async def research(client):
    with client.task("market-research") as t:
        await client.messages.create(
            model="auto",
            messages=[{"role": "user", "content": "Who are the top 3 competitors?"}],
        )

        try:
            with client.step("fetch-pricing"):
                raise TimeoutError("pricing API timed out")
        except TimeoutError:
            pass  # a step can fail without killing the whole task

    # Re-runs only the failed step, with a rebuilt minimal context, not a
    # replay of the whole transcript. The retry lands in the same graph,
    # linked to the node it replaces via depends_on.
    response = await client.resume(t.task_id)

    return client.get_task_graph(t.task_id)

It works in any framework, with no integration code, because parenting uses context variables rather than a wrapper API. A zero-touch LangGraph adapter is included (FluxCheckpointer), which mirrors super-steps into the same task graph.

Recording and resume are both free and fully offline. client.resume() works whenever the process that ran the task still holds its graph, with no network call beyond the provider request itself. What's paid is durability: if that process has since exited, resuming means reconstructing the graph from wherever it was persisted, which needs telemetry to have been on and the hosted platform to have kept a copy. Without both, client.resume() on a task from a dead process raises FluxRecoveryNotInstalled. See fluxcompute.dev for the durable-recovery and dashboard offering.

Telemetry & privacy

The hosted FluxCompute dashboard is in invite-only early access: the public telemetry endpoint is not yet generally available, and without a reachable endpoint the SDK's telemetry is a silent no-op (it never delays or fails your LLM calls). Self-hosted and dev deployments can point the SDK anywhere via FLUX_TELEMETRY_URL / FLUX_GRAPH_EVENTS_URL. For dashboard access, get in touch at fluxcompute.dev.

Telemetry is off unless you pass a fluxcompute_key. With one set, the SDK reports:

  • routing decisions, difficulty scores, token counts, cost, latency
  • execution-graph structure: node names, types, parentage, status, failure reason, model, timings, and error strings, which are diagnostics

Prompt and response text are never sent by default. To include model output in the dashboard (a 500-character preview per node, plus full prompt/output snapshots for failed nodes), opt in explicitly:

client = FluxClient(anthropic_key="...", fluxcompute_key="flx_...",
                    content_capture=True)

Turn everything off with telemetry=False. Content filtering happens before anything leaves the process; your local graph always keeps full output.

Configuration

Keys are read from the environment when not passed explicitly, matching the Anthropic and OpenAI SDK conventions:

Variable Purpose
ANTHROPIC_API_KEY Anthropic provider key
OPENAI_API_KEY OpenAI provider key
FLUXCOMPUTE_KEY FluxCompute key: enables telemetry
FLUX_TELEMETRY_URL Override the telemetry endpoint
FLUX_GRAPH_EVENTS_URL Override the graph-events endpoint

The wire format the SDK sends is documented and versioned in docs/telemetry-contract.md.

Examples

Development

pip install -e ".[dev]"
ruff check fluxcompute/
pytest tests/ -v

We don't take external code contributions, but bug reports are genuinely useful. See CONTRIBUTING.md.

License

Apache-2.0. See LICENSE. Versions 0.1.0–0.2.1 were released under MIT and remain so.

We don't accept external code contributions. See CONTRIBUTING.md for what is useful to us (bug reports, and security issues to security@fluxcompute.dev).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fluxcompute-0.3.1.tar.gz (47.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fluxcompute-0.3.1-py3-none-any.whl (51.3 kB view details)

Uploaded Python 3

File details

Details for the file fluxcompute-0.3.1.tar.gz.

File metadata

  • Download URL: fluxcompute-0.3.1.tar.gz
  • Upload date:
  • Size: 47.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for fluxcompute-0.3.1.tar.gz
Algorithm Hash digest
SHA256 2db7049911e7b8679205f141c4fabfcb8b69a0cc812fac71eee02d658465af36
MD5 0d73fc56b973dbb6339efa2aaef2e8b4
BLAKE2b-256 e9df8f8d795a6818d521999609821dd94aed8d882a9e7dcd58d619f9b5d7d207

See more details on using hashes here.

Provenance

The following attestation bundles were made for fluxcompute-0.3.1.tar.gz:

Publisher: release.yml on fluxcompute/fluxcompute-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fluxcompute-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: fluxcompute-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 51.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for fluxcompute-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1aa40355db1082ffaeb36f18d4da7966cb02a10de25253ed21a913f09f7e4f09
MD5 bbad6e81dfdd4ef3f581535b60c1e771
BLAKE2b-256 0153a01c0a69f0d21010c86e6f65433e309a5b86fcc9f243c0d5a104fc03812a

See more details on using hashes here.

Provenance

The following attestation bundles were made for fluxcompute-0.3.1-py3-none-any.whl:

Publisher: release.yml on fluxcompute/fluxcompute-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page