Skip to main content

render-lab-tasks-llm

Provider-agnostic llm.classify and llm.summarize tasks for Render Workflows. This is a starter subset of the TypeScript pack. Other LLM tasks, including ledger opening/reporting and skill loading, have not yet been ported.

Not yet published to PyPI. Install from this repository:

uv pip install ./packages/tasks-llm

Import app, classify, classify_impl, summarize, and summarize_impl from render_lab_tasks_llm.tasks. Combine pack apps with Workflows.from_workflows. Run wrapped tasks with await ctx.run(classify, input); inject LlmDeps(chat=...) into the raw implementations for tests or custom task wrappers.

Contracts

classify accepts text, labels (objects with name and optional description), optional maxLabels (default 3), model, and ledger. It returns labels, optional reasoning, resolved model, and optional usage. Unknown/non-string labels are removed, duplicates are removed before capping, and malformed model JSON yields an empty label list, matching TypeScript. This is prompt-based classification, not a guarantee of semantic correctness.

summarize accepts text, optional instructions, maxWords (default 120), model, and ledger. It returns trimmed summary, resolved model, and optional usage. The word limit is a prompt target, not hard truncation.

Missing or null optional defaults behave like the TS implementation. Python additionally rejects negative, boolean, and nonintegral maxLabels/maxWords before calling a provider. Zero is valid. Optional result keys are omitted when unavailable. Unknown model prices do not become zero-dollar estimates.

Providers and environment

Credentials and configuration are read when a task runs, never during imports.

Variable Purpose
LLM_MODEL Default provider-prefixed model; otherwise anthropic/claude-opus-4-8, matching the TS snapshot
OPENAI_API_KEY Direct openai/ models, such as openai/gpt-4o-mini
ANTHROPIC_API_KEY Direct anthropic/ models
GEMINI_API_KEY Direct google/ or gemini/ models through Google's OpenAI-compatible endpoint
GOOGLE_GENERATIVE_AI_API_KEY Fallback Google key; OpenAI keys are never used for direct Google requests
LLM_BASE_URL Explicit OpenAI-compatible gateway; preserves the full model identifier
LLM_API_KEY Preferred key for gateways and direct OpenAI; falls back to OPENAI_API_KEY
REDIS_URL Required only for a nonempty ledger without an injected cost-ledger port
LLM_PRICING JSON price overrides keyed by provider-prefixed model; values contain inputUsdPerMTok and optional outputUsdPerMTok
LLM_COST_LEDGER_TTL_SECONDS TTL of at least one second; default 172800, rounded down

The default model and estimated pricing table are copied from the pinned TS snapshot, not a claim of current pricing or availability. Override LLM_MODEL for your account. The example explicitly uses openai/gpt-4o-mini.

Retries, usage, and cost tracking

Provider calls stream internally and assemble their text before returning JSON. Direct OpenAI uses max_completion_tokens; gateways/Google use max_tokens. Official SDK and HTTP retries are disabled; Render owns five retries with a 2000 ms base delay and 2x backoff. Clients close after each call.

Usage includes available input/output token counts and an estimated dollar cost when known. Output accounting preserves the TS max(completion, total-prompt) rule. Estimates ignore caching discounts and price tiers; they are not invoices.

A nonempty ledger appends a JSON cost record to Redis list llm:cost:<ledger> with TTL, compatible with the TS format. Invalid ledger configuration fails before provider spend. Pricing failures without a ledger and append/cleanup failures after spend warn without failing the task, avoiding rebilling solely to repair observability. Inject CostLedgerPort to use another store. The default Redis adapter also disables client retries.

Download files

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

Source Distribution

render_lab_tasks_llm-0.1.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

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

render_lab_tasks_llm-0.1.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file render_lab_tasks_llm-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for render_lab_tasks_llm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 30f91a77446b66b10cda7b677d4644628723277b5302d1be1677fadf6a3fa25f
MD5 3eb0e97d867aef4b8f70c4beb1c3969b
BLAKE2b-256 a6114f892335082c08e9ff29ce3fd1c9cd5dd9e02d69834f8a288f07531290fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for render_lab_tasks_llm-0.1.0.tar.gz:

Publisher: publish.yml on render-lab/render-tasks-python

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

File details

Details for the file render_lab_tasks_llm-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for render_lab_tasks_llm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 883e21dbc9a834359adf5aa45ecc8364e363431422a70fb64ed862d5d05491ca
MD5 575f6d409e59640ca1605fa22c851588
BLAKE2b-256 a0764a52877fecd52315d06584b4593ac6f8478c4f98e14fbc0759a8533eaa22

See more details on using hashes here.

Provenance

The following attestation bundles were made for render_lab_tasks_llm-0.1.0-py3-none-any.whl:

Publisher: publish.yml on render-lab/render-tasks-python

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

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

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