Use Model API with coding agents

Meta Model API works with the coding agents you already use. OpenAI-compatible agents connect to the endpoint at https://api.meta.ai/v1 (Responses or Chat Completions); Anthropic-format agents like Claude Code connect through the Messages API at https://api.meta.ai. Either way, Muse Spark drives your agentic workflows — file edits, shell commands, tool calls, and multi-step coding loops.

This guide covers the general setup pattern and then shows concrete configuration for three popular terminal agents: OpenCode (OpenAI-compatible), Codex (Responses API), and Claude Code (Anthropic Messages).

Start with Muse Code

Muse Code is Meta's first-party coding agent for the terminal and CI, built on Muse Spark. It needs no provider config: install it, run muse, and start building. Use it when you want a ready-made agent that runs the model directly.

The rest of this guide connects third-party agents to Model API. To use Meta's own agent instead, see the Muse Code overview.

Quickstart

Two steps to start coding on Muse Spark:

Step 1: Get an API key. Generate one in the Model API dashboard, then export it:

shell
export MODEL_API_KEY="<your-model-api-key>"

Step 2: Paste this into your coding agent. OpenCode and other self-configuring agents (Goose, Roo, and more) register a provider straight from a prompt. In a session running on your current model, paste:

text
Add a new provider to my config for Meta Model API:
- Provider key: "meta", display name "Meta Model API"
- npm adapter: "@ai-sdk/openai" (targets the Responses API)
- Base URL: https://api.meta.ai/v1
- Model: "muse-spark-1.3"
- Reasoning: true, with reasoningEffort "high", reasoningSummary "auto", and include ["reasoning.encrypted_content"]
- Limits: context 1048576, output 131072
- Modalities: input ["text", "image", "pdf", "video"], output ["text"]
- Read the key from the MODEL_API_KEY environment variable

Select muse-spark-1.3 and start coding. That's it.

Driving Codex or Claude Code, or prefer to write the config yourself? The per-agent setup below has copy-paste configs and notes for each.

How it works

Coding agents act as orchestrators: they take a high-level instruction, decompose it into tool calls (read file, edit file, run command), and loop until the task is complete. Model API provides the inference backend: the agent sends prompts and tool definitions, the model returns completions and tool-call requests.

The connection requires three things:

  1. Base URL: https://api.meta.ai/v1
  2. API key: your Model API key (generate one at dashboard)
  3. Model ID: muse-spark-1.3

Most OpenAI-compatible agents surface these as "custom provider" or "OpenAI-compatible" settings. Anthropic-format agents like Claude Code connect through the Messages API at https://api.meta.ai instead; see Set up Claude Code.

Choosing an API surface

Model API offers two OpenAI-compatible surfaces (Responses and Chat Completions) plus an Anthropic-compatible surface (Messages). Which one your coding agent uses depends on the agent's implementation:

API surfaceWhat it supportsAgent support
Responses API (/v1/responses)Text, images, PDFs (input_file), video (input_video), server-managed conversation stateAgent must explicitly target it
Chat Completions (/v1/chat/completions)Text, images (image_url), PDFs (file content parts), tool calling, streamingUniversal (all OpenAI-compatible agents support this)
Messages (/v1/messages)Text, images, PDFs, video, tool calling, streaming (Anthropic wire format)Anthropic-format agents such as Claude Code

Most coding agents default to Chat Completions when connecting to a custom OpenAI-compatible provider. This is the safest starting point: it handles text generation, image understanding (via image_url content parts), inline document input (via file content parts), tool calling, and streaming out of the box. The Responses API adds video input (input_video), server-side file fetching, and server-managed conversation state. Anthropic-format agents like Claude Code use the Messages API instead.

Surface is auto-selected

You don't need to choose manually in most cases. Your agent's provider configuration determines which surface is used. The guidance below calls out where the choice matters.

Core capabilities

Once connected, Muse Spark drives the standard agent loop regardless of which agent you use:

  • File operations: Read, create, and edit files in your workspace
  • Shell commands: Run builds, tests, git operations, and arbitrary commands
  • Tool calling: Invoke agent-defined tools (function calling over Chat Completions)
  • Multi-step reasoning: Plan and execute complex tasks across multiple turns

Multimodal input

Support for images, PDFs, and video depends on how the agent handles media attachments:

Input typeVia Responses APIVia Chat Completions
Images✓ Direct paste/upload✓ Native: pass as image_url content parts (base64 or URL)
PDFs✓ Native via input_file✓ Native: pass as a file content part (inline base64 or uploaded file_id)
Video✓ Native via input_videoNot available on this surface; use the Responses API

Images and PDFs are accepted on both surfaces: Responses API takes them as input_image and input_file, and Chat Completions as image_url and file content parts. Video is Responses-only, via input_video. The Responses API also adds server-side file handling, such as fetching a document from a URL or referencing one uploaded through the Files API.

If media doesn't reach the API, it's almost always a client-side configuration issue, not an API limitation. Two things to get right in your harness:

  1. Use the SDK connector that matches the surface you want: @ai-sdk/openai targets the Responses API; @ai-sdk/openai-compatible targets Chat Completions.
  2. Declare the model's modalities accurately: set input: ["text", "image", "pdf", "video"]. Some agents strip image or file parts from a request when a custom provider is missing that modality metadata, so an accurate connector-plus-modalities setup keeps your attachments intact.

Set up OpenCode

OpenCode(opens in new tab) is a terminal-based coding CLI. It supports multiple AI SDK adapters, giving you a choice between Chat Completions and the Responses API.

Configuration

OpenCode can configure itself. Launch it with your default model active, then ask the model to register Model API as a new provider. Alternatively, edit the config file directly.

Option A: Self-configuration

Launch OpenCode with your default model active, then paste this prompt:

text
Add a new provider to my opencode.json config with the following details:
- Provider key: "meta"
- Provider name: "Meta Model API"
- npm adapter: "@ai-sdk/openai"
- Base URL in options: "https://api.meta.ai/v1"
- Model key: "muse-spark-1.3" with name "muse-spark-1.3"
- Capabilities: reasoning = true
- Limits: context = 1048576, output = 131072
- Modalities: input = ["text", "image", "pdf", "video"], output = ["text"]
- Model options: reasoningEffort = "high", reasoningSummary = "auto", include = ["reasoning.encrypted_content"]

Once OpenCode writes the config, run /connect, select the meta provider, and supply your API key when prompted. Restart OpenCode and select Muse Spark.

Option B: Manual config

Add this block to your opencode.json:

opencode.json: Responses API adapter (recommended)
{
"provider": {
"meta": {
"name": "Meta Model API",
"npm": "@ai-sdk/openai",
"options": {
"baseURL": "https://api.meta.ai/v1"
},
"models": {
"muse-spark-1.3": {
"name": "muse-spark-1.3",
"reasoning": true,
"limit": {
"context": 1048576,
"output": 131072
},
"modalities": {
"input": ["text", "image", "pdf", "video"],
"output": ["text"]
},
"options": {
"reasoningEffort": "high",
"reasoningSummary": "auto",
"include": ["reasoning.encrypted_content"]
}
}
}
}
}
}

The include: ["reasoning.encrypted_content"] setting is what carries Muse Spark's reasoning across turns. OpenCode replays the encrypted blob on every subsequent request, so the model retains its prior reasoning during multi-step tool loops and during OpenCode's automatic context compaction. Without it, Muse Spark loses its own reasoning between calls. See Reasoning items in multi-turn input for the underlying mechanism.

If you don't need reasoning continuity or native PDF input, the simpler @ai-sdk/openai-compatible adapter is available as a fallback (Chat Completions, no encrypted-reasoning replay). Image input still works: OpenCode forwards read-attached images as image_url parts on this adapter too.

opencode.json: Chat Completions adapter (fallback)
{
"provider": {
"meta": {
"npm": "@ai-sdk/openai-compatible",
"name": "Meta Model API",
"options": {
"baseURL": "https://api.meta.ai/v1"
},
"models": {
"muse-spark-1.3": {
"name": "muse-spark-1.3",
"limit": {
"context": 1048576,
"output": 131072
}
}
}
}
}
}
Store keys via /connect

Store your API key via /connect, not in the config file. If you must set it inline for local testing, use options.apiKey, but never commit a real key.

After editing, restart OpenCode for the new provider to take effect.

Supported features

CapabilityResponses API adapterChat Completions adapter
Chat and Q&A
File read/edit/create
Shell commands
Image input✓ Direct paste✓ Forwarded via read (file path)
PDF input✓ Direct pasteNot attached over this adapter (use @ai-sdk/openai)
Local TypeScript tools
MCP server tools
Cross-turn reasoning continuity✓ Encrypted reasoning replayed automatically⚠️ Not preserved — each turn reasons from scratch (see warning below)

OpenCode-specific notes

  • Two adapters, different tradeoffs. @ai-sdk/openai is the recommended adapter: it enables direct multimodal input (including PDF) and replays encrypted reasoning across turns, so Muse Spark retains its prior reasoning during tool loops and compaction. @ai-sdk/openai-compatible is simpler to configure and still forwards read-attached images as image_url parts, but doesn't attach PDFs over this adapter (use @ai-sdk/openai for PDF input) and does not replay encrypted reasoning.
  • Local tools are straightforward. Drop TypeScript files in .opencode/tools/ and the model discovers and invokes them automatically.
  • Restart required after config changes. OpenCode requires a full restart to load new provider registrations.

Set up Codex

Codex(opens in new tab) is OpenAI's open-source terminal coding agent. It drives Muse Spark over the Responses API, so reasoning carries across turns automatically.

Configuration

Register Model API as a provider in your config.toml and point the default model at it:

~/.codex/config.toml
model = "muse-spark-1.3"
model_provider = "meta"
model_reasoning_effort = "high" # none | minimal | low | medium | high | xhigh | max
model_reasoning_summary = "auto"
model_context_window = 1048576 # Muse Spark: 1M-token context
model_supports_reasoning_summaries = true
model_auto_compact_token_limit = 900000