№ 0239GitHub
Meta Model API cookbook
Meta's official recipes for building agents and coding tools on the Model API with Muse Spark 1.3, covering API basics, multi-agent patterns and end-to-end use cases via OpenAI- and Anthropic-compatible SDKs.
Meta Model API cookbook
Recipes for building agents and coding tools on the Meta Model API, covering API fundamentals,
agent patterns, and end-to-end use cases.
Meta Model API lets you build with Muse Spark using the
tools you already run: it's drop-in compatible with the OpenAI
SDK, the Anthropic SDK, and agent CLIs like OpenCode and Claude Code.
Point your client at
the Model API base URL, set your key, and keep the rest of your code. Each recipe is a
self-contained, copy-paste starting point that proves a capability and gives you something to build
on. The default model is Muse Spark (muse-spark-1.3), which has a 1,048,576-token context
window; the preview is free.
Getting started
You need a Model API account and an API key. Store the key as
an environment variable so it stays out of your code:
export MODEL_API_KEY="LLM|{numeric_id}|{secret}"
pip install openai
import os
from openai import OpenAI
# The OpenAI SDK does not auto-read MODEL_API_KEY, so pass it explicitly.
client = OpenAI(
base_url="https://api.meta.ai/v1",
api_key=os.environ["MODEL_API_KEY"],
)
response = client.chat.completions.create(
model="muse-spark-1.3",
messages=[{"role": "user", "content": "Hello, world!"}],
)
print(response.choices[0].message.content)
Recipes
This cookbook mirrors the three sections of the Meta Model API cookbook website. Each recipe
is a self-contained, copy-paste starting point. Start with API fundamentals to learn the
API primitives, then move into agent patterns and end-to-end use cases.
1. API fundamentals
Prove each API primitive works and get a starting point you can build on.
| # | Recipe | What it does |
|---|---|---|
| 01 | Quickstart: chat completions | Make your first Muse Spark call by pointing the OpenAI SDK at one new base URL. |
| 02 | Streaming responses | Render tokens as they generate and read the final usage chunk. |
| 03 | Tool and function calling | Detect tool calls and run the execute-and-feed-back loop. |
| 04 | Structured output | Get schema-guaranteed JSON that parses on the first try. |
| 05 | [Prompt cachi |




ChatForm
Tgmlabs