Skip to content

Managed AI ​

Give every notebook a working AI assistant without asking users for their own API key. When managed AI is on, marimohub points marimo's assistant at a provider you configure and pays for. Chat, autocomplete, and "generate with AI" work when someone opens a notebook.

It's optional and off by default. Turn it on by setting one upstream provider; provider credentials stay on the server and are never exposed to notebook code.

Configuration ​

Select Bedrock or an API-key-backed OpenAI-compatible upstream. When configured, managed AI is injected into every session deployment-wide.

Amazon Bedrock ​

The hub uses Bedrock Converse for Claude chat and SQL generation, and the OpenAI-compatible endpoint for other requests. It signs requests with its AWS identity through SigV4. Credentials stay outside sandboxes.

bash
MARIMOHUB_AI_BACKEND=bedrock
MARIMOHUB_AI_AWS_REGION=eu-west-1
MARIMOHUB_AI_MODEL=eu.anthropic.claude-opus-4-7
# MARIMOHUB_AI_ALLOWED_MODELS=model-a,model-b

The runtime identity needs bedrock:InvokeModel and bedrock:InvokeModelWithResponseStream for the configured inference profiles or foundation models. On EKS, use IRSA or EKS Pod Identity; the standard AWS credential chain also supports local development credentials.

When MARIMOHUB_AI_ALLOWED_MODELS is unset, Bedrock is restricted to MARIMOHUB_AI_MODEL. Set an explicit comma-separated allowlist to expose more models.

Claude IDs support anthropic., regional profiles such as eu.anthropic. and us.anthropic., and global.anthropic. profiles. The runtime identity must have access to the model or profile in the selected region.

Startup skips the AI probe only when the default and all allowed models are Claude, to avoid billable inference. Mixed allowlists still probe the OpenAI endpoint. Claude model access is checked on the first request.

Claude supports text chat with JSON or streaming responses, without tools, images, or Responses translation. See the proxy contract for supported fields.

OpenAI-compatible provider ​

Point the hub at any OpenAI-compatible provider. Notebooks get the AI assistant with no key of their own — the hub holds the real key server-side and proxies requests through /api/ai/v1.

bash
MARIMOHUB_AI_BACKEND=openai-compatible
MARIMOHUB_AI_UPSTREAM_BASE_URL=https://api.openai.com/v1
MARIMOHUB_AI_UPSTREAM_API_KEY=sk-...          # real key, held server-side
MARIMOHUB_AI_MODEL=gpt-4o-mini                 # default model offered to users
# MARIMOHUB_AI_ALLOWED_MODELS=gpt-4o-mini,gpt-4o   # optional allowlist

Reuses the session secret

Per-session tokens are signed with MARIMOHUB_AUTH_SESSION_SECRET, so that must be set too (it also signs login cookies). The real upstream key is never written into a sandbox.

Works with OpenAI, OpenRouter, LiteLLM, W&B Inference, or Anthropic's OpenAI-compatible endpoint. See Managed AI for the provider table.

The full set of variables:

VariableRequiredDescription
MARIMOHUB_AI_BACKEND—none (default), bedrock, or openai-compatible.
MARIMOHUB_AI_AWS_REGIONBedrockAWS region for Bedrock. Falls back to AWS_REGION or AWS_DEFAULT_REGION.
MARIMOHUB_AI_UPSTREAM_BASE_URLAPI keyUpstream OpenAI-compatible base URL, e.g. https://api.openai.com/v1. The proxy POSTs to <base>/chat/completions.
MARIMOHUB_AI_UPSTREAM_API_KEYAPI keyThe real upstream key. Held server-side; never injected into a sandbox.
MARIMOHUB_AI_MODELyesDefault model id surfaced to marimo, e.g. gpt-4o-mini.
MARIMOHUB_AI_ALLOWED_MODELSnoComma-separated allowlist; off-list requests fall back to the default model. Unset allows any model on OpenAI-compatible upstreams; on Bedrock it restricts to MARIMOHUB_AI_MODEL.
MARIMOHUB_AI_UPSTREAM_PROJECTnoOptional OpenAI-Project header forwarded upstream (e.g. W&B Inference entity/project attribution).
MARIMOHUB_AI_MAX_TOKENSnoOutput token budget for project chat, SQL generation, and the notebook assistant.
MARIMOHUB_AI_RULESno[ai] rules — custom assistant instructions.
MARIMOHUB_AI_TOKEN_TTL_SECONDSnoAI session-token lifetime in seconds (default: 3600). Shorter lifetimes reduce the revocation window.

Managed AI also requires MARIMOHUB_AUTH_SESSION_SECRET — the per-session tokens are signed with it (the same secret that signs login cookies).

With an allowlist, the notebook picker shows only the default and allowed models as marimohub/<model-id>, routed through the managed AI proxy. Without an allowlist, OpenAI-compatible upstreams keep marimo's model catalog. Bedrock shows only the default model. Allowlist changes apply to new sessions.

Providers ​

For API-key-backed providers, any OpenAI-compatible endpoint works. Set MARIMOHUB_AI_UPSTREAM_BASE_URL to the provider's base and MARIMOHUB_AI_MODEL to one of its model ids:

ProviderBase URLNotes
OpenAIhttps://api.openai.com/v1gpt-4o-mini, gpt-4o, …
OpenRouterhttps://openrouter.ai/api/v1One key, hundreds of models across vendors.
W&B Inferencehttps://api.inference.wandb.ai/v1Set MARIMOHUB_AI_UPSTREAM_PROJECT=entity/project.
Anthropic (compat.)https://api.anthropic.com/v1Anthropic's OpenAI-compatible endpoint.
LiteLLM / self-hostedhttps://<your-litellm-host>/v1Front many providers behind one gateway.

How it works ​

  1. Inject. At session start, marimohub sets XDG_CONFIG_HOME and writes a marimo.toml into that sandbox-local config directory, outside the notebook's files. The config registers a custom AI provider pointed at marimohub's own proxy using a short-lived, session-scoped token as the api_key.
  2. Proxy. marimohub hosts an OpenAI-compatible endpoint at /api/ai/v1. It verifies the session token, authenticates the upstream request server-side, and streams the response back.

Notebook kernels run untrusted code, so provider credentials are never written into a sandbox — only a minted, expiring, session-scoped token. This mirrors how Workload Identity Federation avoids long-lived storage keys.

Token revocation is not immediate

The proxy checks token signatures, expiration, and user suspension on each request. It rejects suspended users and fails closed if it cannot check suspension status. Stopping a session or removing project access does not invalidate its token.

The default lifetime is one hour. Set MARIMOHUB_AI_TOKEN_TTL_SECONDS to a lower value to reduce the revocation window. AI access ends when the token expires, even if the notebook session remains active.

Project chat ​

With managed AI enabled, users can start conversations on the project's Chat page. Only the person who starts a conversation can read or change it. Service accounts cannot use chat.

Chat offers the hub's MCP tools under your project permissions. Most hub reads run without consent. Data previews ask first because they can start compute and send data to the model provider.

For external MCP tools, the consent card shows the server, destination, tool, and arguments, with credentials masked. Always allow covers all allowed reads on that server in this project, or one write tool the server explicitly marks as non-destructive. Other writes ask every time. Editing the integration requires fresh consent. Hub and external tools share 24 calls per turn. If discovery fails, chat names the unavailable server and continues.

Each turn inherits the current instructions and skills from active org and project Agent context integrations. Chat receives skill names and descriptions, then loads complete skills with load_agent_skill. Skills without valid descriptions remain available by name. This context remains subject to deployment rules and tool permissions. Claude Code and OpenCode settings apply only to sandbox agents.

Review the submitted code or source on the consent card, then allow or deny the call. Chat rejects code or source longer than 20,000 characters so you can review each call in full. For execute_code and other eligible tools, Always allow remembers your choice for that tool in this project. Irreversible actions, create_branch_notebook, and run_query ask every time. Manage saved permissions under Permissions in chat or with project_conversations.

Replies keep running if the browser disconnects: a reload re-attaches to the live stream on the same instance and otherwise shows the saved progress. Stop requests and consent decisions are written to the conversation record, so they reach the instance running the turn without session affinity. A stopped or interrupted reply leaves a saved task to continue or dismiss.

If Python execution fails, the model receives up to the last 3,000 characters of redacted stderr, including any traceback there. The transcript shows a short error summary.

The model reads earlier turns as text and can call tools for fresh results. The transcript shows redacted tool previews that omit code and large outputs and mask credentials and URLs. Saved tasks keep bounded tool results with credentials masked so the model can resume. Open a tool call to see the notebooks and jobs it touched.

VariableDefaultDescription
MARIMOHUB_AI_CHATonoff disables project chat; the notebook assistant proxy stays on.
MARIMOHUB_AI_CHAT_TASK_TIMEOUT_SECONDS300Wall-clock budget for one reply, including tool calls (30–900).
MARIMOHUB_AI_CHAT_PERMISSION_TIMEOUT_SECONDS300How long a consent card waits before the call is skipped (30–900).

Project chat requires tool calling. Bedrock Claude uses Converse. The Workers example has no chat model and hides the Chat page.

Each model call defaults to 8,192 output tokens. Set MARIMOHUB_AI_MAX_TOKENS to change the budget (maximum 65,536). For direct OpenAI requests, the AI SDK selects the token-limit field for the model. Other OpenAI-compatible endpoints receive max_tokens.

Proxy contract ​

The proxy exposes the OpenAI endpoints marimo needs. Each requires a bearer session token. The hub authenticates upstream requests.

  • POST /api/ai/v1/chat/completions — forwards to the upstream, using Converse for Bedrock Claude and SSE for stream: true. The hub resolves model against the configured allowlist.
  • POST /api/ai/v1/responses — forwards requests to the upstream Responses API. The provider and model must support Responses. There is no Converse translation.
  • GET /api/ai/v1/models — lists allowed models, or the default if no allowlist is set.

The Bedrock Claude bridge supports:

  • Text in system, developer, user, and assistant messages. System and developer messages combine into system instructions.
  • stream, temperature, top_p, and stop.
  • Token limits, in precedence order: max_completion_tokens, max_tokens, then MARIMOHUB_AI_MAX_TOKENS. The configuration supplies a default, not a hard cap.

The bridge ignores other fields, tool messages, tool calls, and non-text content. Tool-dependent clients, including OpenCode agents, need a provider with tool support.

Request bodies have a 10 MB limit, including embedded files. Larger requests receive HTTP 413 before reaching the provider.

Other OpenAI endpoints, including embeddings and images, are not exposed.

What the user can override ​

The injected config sits at the user-config tier, so a user who explicitly sets [tool.marimo.ai] in their own pyproject.toml still overrides it — a deliberate bring-your-own-key escape hatch. With managed AI off (MARIMOHUB_AI_BACKEND=none), the assistant only works for users who supply their own key in marimo's settings.

OpenCode uses the same proxy through a temporary marimohub provider. Project opencode.json files and /connect providers can override it. The token expires at the configured TTL. Restart OpenCode to get a new token.

Provider-agnostic. Deploy anywhere.