Skip to main content

AI Commands (modal ai)

Configure the LLM used by modal ai suggest-rule. Config is stored at $MODALITY_HOME/.modality/ai.json (or ~/.modality/ai.json).

Set Provider

modal ai set --provider openai|anthropic|grok|bedrock|ollama|cursor-agent [--model] [--base-url] [--api-key] [--region] [--save-key]

Options:

OptionDescription
--provider <PROVIDER>openai, anthropic, grok, bedrock, ollama, or cursor-agent
--model <MODEL>Model id (provider default if omitted)
--base-url <BASE_URL>API base URL (openai, anthropic, grok, ollama)
--region <REGION>AWS region (bedrock)
--api-key <API_KEY>API key (openai, anthropic, grok)
--save-keyPersist the API key in ~/.modality/ai.json (mode 0600)
modal ai set --provider openai
modal ai set --provider anthropic
modal ai set --provider grok
modal ai set --provider bedrock --region us-east-1
modal ai set --provider ollama
modal ai set --provider cursor-agent

--save-key is only for openai, anthropic, and grok. Bedrock uses the AWS credential chain (AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY / AWS_SESSION_TOKEN, a shared credentials file, or an instance role). Do not persist AWS secrets in ai.json. Ollama needs no API key by default. cursor-agent uses the Cursor CLI (agent or cursor-agent on PATH): run agent login, or set CURSOR_API_KEY. Override the binary with MODAL_AI_CURSOR_AGENT.

Defaults:

ProviderBase URLModel
openaihttps://api.openai.comgpt-5.6-luna
anthropichttps://api.anthropic.comclaude-sonnet-4-20250514
grokhttps://api.x.aigrok-3
bedrockregion us-east-1anthropic.claude-sonnet-4-20250514-v1:0
ollamahttp://127.0.0.1:11434llama3.2
cursor-agentCursor CLI in the contract directoryaccount default (auto)

API key resolution, first match wins:

  1. --api-key on set / suggest-rule
  2. MODAL_AI_API_KEY
  3. Provider env: OPENAI_API_KEY, ANTHROPIC_API_KEY, XAI_API_KEY, CURSOR_API_KEY
  4. Optional API key saved in ai.json only with --save-key

Show

modal ai show

Prints the configured provider, model, and a redacted API key. If nothing is configured, run modal ai set --provider openai|anthropic|grok|bedrock|ollama|cursor-agent.

Unset

modal ai unset

Removes ~/.modality/ai.json.

Suggest a Rule

modal ai suggest-rule <PROMPT>

Calls the configured provider and prints one Modality formula for modal add-rule. Encodings follow the formula cookbook. Witness models for modal add-rule follow the model cookbook. The Cursor skill packages/modality-skill/SKILL.md points at the same files. If no provider is configured, the command fails with a hint to run modal ai set.

With --provider cursor-agent, suggest-rule runs the Cursor CLI in the contract directory (--dir or the current directory) and adds docs/language plus packages/modality-skill so the agent can read those files. The default is --print: a one-shot formula on stdout. Pass --interactive for an Ask-mode session so the agent can read state/, rules/, and model/.

modal ai suggest-rule "after this commit either alice or bob must sign"
modal ai suggest-rule --interactive "after this commit either alice or bob must sign"
[] always([-signed_by(/parties/alice.id) -signed_by(/parties/bob.id)] false)

That printed formula is example output; yours may differ.