Skip to content

About

Agent-operated CLI and Python library for sponsoring Modal compute grants with budgets, isolated access, and expiry tracking

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

Compute grants

A small CLI and Python library for agents administering GPU MODE compute grants on Modal and inference grants on OpenRouter. One private JSON register tracks both providers; the sponsor pays the provider directly. No money or credit balance is transferred to a recipient.

Modal OpenRouter
Recipient access Own Modal account; Member with access to one restricted environment Ordinary inference API key; no organization invitation
Monthly allowance Environment compute budget, configured in the dashboard Native per-key monthly limit, including BYOK inference estimates
Expiry External job revokes access and stops workloads Native key expiry, plus external cleanup that disables the key
Setup Dedicated Team/Enterprise workspace with verified restrictions Sponsor account and Read/write management key

Provider setup and funding are separate operator work. OpenRouter grants can be staged offline before an account is ready; initialization does not provision an account, purchase credits, or issue a key.

Install

uv tool install --python 3.12 --with-executables-from modal \
  git+https://github.com/gpu-mode/compute-grants.git

Supports macOS/Linux and Python 3.11–3.15. Modal is pinned to 1.7.0. This installs both gpu-grants and modal; OpenRouter-only use requires no Modal login or workspace.

OpenRouter grant

Stage an authorized grant locally, including in an existing Modal register:

gpu-grants --json init --provider openrouter
gpu-grants --json add alice-openrouter --provider openrouter \
  --email alice@example.com --monthly 100 --until 2027-01-01 \
  --project "Inference research"
gpu-grants --json show alice-openrouter

These commands need no provider credentials and create no remote key. When the sponsor account is ready, load a Read/write management key into OPENROUTER_MANAGEMENT_KEY, preferably scoped to the intended OpenRouter workspace. Activate locally with a new file in an existing private directory outside every Git worktree:

gpu-grants --json activate alice-openrouter \
  --key-file /absolute/private-directory/alice-openrouter.key
gpu-grants --json message alice-openrouter

Activation creates and verifies a limited inference key. Its raw secret is written only to the new mode-0600 file, never to stdout or the register. message prints instructions without the key and sends nothing. Deliver the file only through an authorized private channel; never share the management key. See the OpenRouter guide for account setup, usage accounting, and interrupted-key recovery.

Modal grant

Configure a Modal profile authenticated as an Owner or Manager in a dedicated grants workspace before starting. The workspace needs a Team or Enterprise plan for restricted environments and environment budgets.

Before inviting recipients, enable and verify manager-only environment creation for the workspace. Otherwise Members can create environments outside their grant budget. There is no public CLI setter; if the dashboard does not expose the control, Modal must enable and confirm it. Restricting existing environments alone is insufficient. A Starter workspace does not meet the grant prerequisites; the tool does not upgrade plans.

An agent follows this sequence for an authorized grant. Replace the example recipient, amount, expiry, profile, and workspace with the agreed values.

gpu-grants --json init --profile gpu-mode-grants --workspace gpu-mode-grants
gpu-grants --json add alice --email alice@example.com --monthly 100 \
  --until 2027-01-01 --project "Kernel research"
gpu-grants --json show alice

Follow the returned next_actions in the Modal dashboard:

  1. Verify manager-only environment creation is enabled for this workspace, through an exposed setting or confirmation from Modal.
  2. Verify every environment, including main, is restricted with default member role No Access. Set an overall workspace usage budget.
  3. Set grant-alice's monthly compute budget to exactly $100, before granting access.
  4. Invite alice@example.com as a workspace Member only after those checks. After acceptance, verify the matching email and Modal username. Members must not have access to other environments through direct roles or groups.

After observing the saved settings and accepted membership, the agent runs:

gpu-grants --json activate alice --username alice --setup-confirmed \
  --manager-only-creation-confirmed
gpu-grants --json message alice

The confirmation flags record the agent's completed checks; they do not request human approval or enable remote controls. --manager-only-creation-confirmed records manager_only_creation_confirmed_at locally. If login, permissions, or Modal enablement block setup, report the specific action needed. message produces recipient instructions without sending them.

Operate and end grants

gpu-grants --json list
gpu-grants --json show alice
gpu-grants --json usage alice
gpu-grants --json expire
gpu-grants --json expire --apply
gpu-grants --json revoke alice

expire previews due grants across providers; --apply revokes them and retries interrupted revocations. revoke NAME requests immediate revocation. Failures for one grant/provider do not prevent expiry or usage work for others; inspect ok, errors, and partial results.

For Modal, revocation removes access and attempts workload cleanup. Check the result and retry incomplete cleanup. A successful cleanup reports that no running apps or containers were observed; retained storage and reservations still need review.

For older active Modal grants without manager_only_creation_confirmed_at, show returns an audit action. Verify the workspace control before treating their isolation as confirmed.

After reviewing and resolving retained storage/reservations in the dashboard:

gpu-grants --json close alice --storage-reviewed

For OpenRouter, revocation disables the key and verifies it is disabled; it does not delete the key. Close the revoked grant with close alice-openrouter, without --storage-reviewed.

Expiry is midnight Pacific at the start of the --until date. OpenRouter activation converts this to a native UTC expiry timestamp; the monthly allowance instead resets on the first at midnight UTC. The package installs no scheduler: arrange an external job or agent to run expire --apply. Modal requires that job to enforce expiry; OpenRouter's native expiry ends key access and the job records verified cleanup. There is no grant renewal or native-expiry update command.

Agent and Python interfaces

gpu-grants --json <command> returns a structured result with ok, command, message, data, and next_actions; failures also include error and exit with status 1. Inspect ok and follow the next actions; never treat an attempted command as completed work. Existing list --json and usage --json forms remain supported.

For a Python project, install with uv add git+https://github.com/gpu-mode/compute-grants.git, then use the same arguments:

from grants import execute

result = execute(["show", "alice"])
if not result["ok"]:
    print(result["error"])
print(result["next_actions"])

Read AGENTS.md for operating instructions, the Modal workflow and screenshots for dashboard controls, and the OpenRouter guide for inference keys. The default register is ~/.local/share/gpu-mode-grants/grants.json; --state PATH selects another file. It contains recipient emails and provider metadata, uses a single-operator lock, and should be backed up privately. OpenRouter records include the key hash, generated name, and local key-file path, never the raw key.

The package separates shared state and validation (grants/core.py), command orchestration (grants/cli.py), and provider adapters (grants/providers/modal.py and openrouter.py). New version-1 registers use a providers map. Existing version-1 registers with root-level Modal profile/workspace and no grant provider tags remain supported; an omitted provider means Modal. init --provider openrouter adds that provider to an existing register. Grant names are unique across providers; one email may have one open grant per provider, using distinct names.

What the allowance covers

OpenRouter calls spend the sponsor account's credits. The native key limit uses a UTC calendar month and includes BYOK inference estimates. Usage reports keep OpenRouter credit spend (including BYOK platform fees) separate from external BYOK inference-cost estimates; neither is a complete third-party invoice. Only the current UTC month's key counters are available through this adapter. Preserve private usage snapshots for history. Account funding is not automated.

For Modal:

  • Grants fund monthly compute usage, not a one-time credit transfer or an all-inclusive invoice limit. Environment budgets exclude storage, network egress, and reservations.
  • Budgets are soft scheduling limits: Modal checks cached usage when scheduling new containers. Existing workloads may continue, and usage can overshoot the threshold. This tool adds no budget watchdog or guaranteed stop at an exact dollar amount.
  • Keep a workspace usage budget as an additional workspace-wide threshold. A separate workspace spend limit applies to net charges after credits. Shared workspace usage can reach its threshold before an individual grant does.
  • Recipients have Contributor access to their environment, including its apps, logs, secrets, and files. Budget changes require Workspace Owner or Manager access. Environment roles do not guarantee billing API privacy: service-user credentials can read billing summaries, and human Member visibility is not verified by this workflow. Keep production resources in a separate workspace.
  • Ending a grant does not cancel the workspace subscription or delete retained resources. Setup confirmation reflects an agent's observation, not a budget API write or continuous configuration audit.

MIT license. Modal permissions · Modal budgets · OpenRouter management keys

About

Agent-operated CLI and Python library for sponsoring Modal compute grants with budgets, isolated access, and expiry tracking

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages