Muse in Code

How to call Muse from your own code: the key, the address and the model name, three ways in (a raw web request, the OpenAI SDK, the Anthropic SDK), instructions and limits, and what to do when a call fails.

7:05 video9 min readWatch on YouTube

Muse in Code

How to call Muse from your own code: the key, the address and the model name, three ways in (a raw web request, the OpenAI SDK, the Anthropic SDK), instructions and limits, and what to do when a call fails.

You come away able to assemble a working call, to tell which base URL goes with which SDK, to read the error JSON and know what 401, 404, 429 and 5xx mean, and to decide when a plain web request is enough.

Honest about how it was made: this film was drafted in Muse and then cleaned up and rebuilt with Claude. The film corrects a common misreading: the OpenAI SDK base URL includes /v1 (https://api.meta.ai/v1) while the Anthropic SDK takes the bare host. It shows Meta's own steps for creating a key, notes the Anthropic SDK's auth_token and required max_tokens, and says retry on 429, 500 and 503 but stream instead of retrying a 504. The view that plain web requests are enough is the lecture's own judgment, not attributed to anyone else.

A note that opens the film Muse drafted this, Claude cleaned it up. This film began as a rough draft made with Muse. Muse runs on a simple model called Spark, and Spark makes a lot of mistakes, so Claude cleaned the draft up. The method is the point: draft in Muse, then finish in Claude or Codex. One kind of mistake we looked for: a draft Muse diagram of two big boxes and a check mark under a question about whether a non-technical person could use it, with both boxes empty. A diagram that shows nothing teaches nothing, so Claude replaced diagrams like this one.

Narrated by Liam, in for Bear. Narration is an AI voice; the film was made with AI tools.

Chapters 0:00 Muse note 0:28 The idea and the key terms 0:59 The Key 1:34 The Address 2:27 Three Ways In 3:25 Instructions And Limits 4:11 When It Breaks 5:14 The Stance 6:01 Recap 6:32 Your Turn

Your turn Paste this into Claude: Write the smallest Python script that sends one question to Meta's Muse Spark through the OpenAI SDK. Read my key from an environment variable, never from the file itself. Tell me which base URL and model name you used, and explain what an HTTP 401 and an HTTP 404 from this API mean. Then check two things yourself. Does the script read the key from the environment? And does the base URL it used match the one in Meta's docs?

Sources shown on screen Meta's public docs at dev.meta.ai (overview, quickstart, authentication, protocols, SDKs, API reference, error handling, models, pricing and rate limits, cookbook), captured 2026-10-07. Narration follows a Muse course taught by Andrew Brown, named on screen. Nothing here is a product endorsement.

Part of the playlist Muse for Educational AI.

@NikBearBrown

What this video covers

  • 0:00 — Muse note
  • 0:28 — The idea and the key terms
  • 0:59 — The Key
  • 1:34 — The Address
  • 2:27 — Three Ways In
  • 3:25 — Instructions And Limits
  • 4:11 — When It Breaks
  • 5:14 — The Stance
  • 6:01 — Recap
  • 6:32 — Your Turn

Transcript

A lightly formatted transcript of the video, with timestamps so you can jump to any section on YouTube.

Muse note

[0:00] A note before we start. This film began as a rough draft made with Muse. Muse runs on a simple model called Spark and Spark makes a lot of mistakes. So Claude cleaned this draft up. The method is the point draft and Muse then finishing Claude or Codeex. Here is the kind of mistake we look for. A draft diagram from Muse. Two big boxes and a check mark under a question about whether a non-technical person could use it. Both boxes are empty. A diagram that shows nothing teaches nothing. So Claude replaced diagrams like this one. Hello,

The idea and the key terms

[0:29] This is Liam in forbear. You may know Muse as a chat window. Today it leaves the window. Your own code calls Muse over the internet three different ways and you learn to read the errors when a call breaks. Six terms. The API key, a secret string that proves who is calling. The base URL, the front part of every address you call the endpoint, one path on the server that does one job. The SDK, a library that wraps the web request in functions. REST, using a service by sending it plain web requests. and the status code, the number that says how the call went.

The Key

[0:59] Every call to Muse carries three things. Who is asking your key, where the call goes, an address, and what you want, a model name, and a message. Leave one out, and the API answers with an error. You make the key in Meta's dashboard once you log in. Open the API keys tab, click create, name it, and copy it right away because you only see it once. These are Meta's own steps. The dashboard needs your login. Then keep the key out of your code. store it in an environment variable and let your program read it from there. A key typed into a file can end up in version control and anyone who finds it can send requests as you. Now

The Address

[1:34] The address a call goes to a base URL plus a path for the open AI SDK. The base is api.ma.ai/v1. The SDK adds the rest itself/ chat/completions. The anthropic SDK works differently. Its base is only the host with no /v1 because it adds /v1/ messages itself. The course calls that a quirk. Either way, both land on the same doors. Meta's own page lists the three request formats and where each one lives, responses, chat completions, and messages. All three run the same models for the same price. Meta recommends responses for new work and the other two for code that already exists. The model name picks the model and the tier 2. Muse Spark 1.3 is the standard tier. Add- contributor and you get the cheaper tier that trains on your data. A name that doesn't exist comes back as a 404. Way one, a raw web

Three Ways In

[2:28] Request, no library. One post to the address, a header carrying your key, a header saying the body is JS and the body itself, a model name, and your messages. What comes back is JSo2. The reply text sits inside it. Choices. The first item message content meta's doc spell that path out in one line and your code follows it. Way two the open AI SDK. Build a client with your key and meta's base URL. Then call chat completions create. Those two arguments are the only meta-pecific part. The rest is code you may already have written for open AI. Way three, the anthropic SDK. The base is the bare host. The key goes in as an O token and max tokens is required. So you must say how long the answer may be. The reply text is content first block text. Line the two up and four things differ. The base URL, the name of the key argument, whether max tokens is required, and where the reply text lives. Everything else is the same

Instructions And Limits

[3:25] Idea. Next, instructions. The model remembers nothing between calls. So for conversation, you send the whole history every time. Your messages, its replies, and then the new question. The array grows with each turn. To steer behavior, add a developer message, tone, format, rules. When it conflicts with the user's message, the developer message wins. The older system role still works at the same level, but Meta says to prefer developer. The anthropic format has no instruction role inside the array. Instructions go in a separate system field outside messages and messages hold only user and assistant turns. Max tokens caps the answer. Hit the cap and the answer stops where it is and the response says why. Stop reason max tokens. Set it too low and you get half an answer. When a call fails, you still

When It Breaks

[4:13] Get jso n with four fields. Message says what went wrong and meta's docs call it the most reliable field. Type is the category. Pam names the field at fault. Code is often null. First is the service up. A status and point answers without a key. Now a real call with no key. 401 authentication error. Invalidated PI key. The message tells you exactly what to fix. Then sort errors by number. A 400, 401, 402, 403, or 404 means fix something. The request key, billing, permission, or model name. A 429, 500, or 503 means wait and try again. When you do retry, don't hammer. Meta suggests starting at half a second, doubling the weight after each failure, and adding a little randomness so many clients don't retry in lock step. If the response has a retry after header, honor it. Andrew Brown, who teaches the course, debugged his calls by reading these messages. The loop, run, read, fix one thing, run again. Here it is on two fixes from Meta's quick start. A missing key, then a wrong model name. Here is

The Stance

[5:15] The judgment this lecture lands on. Plain web requests are enough because an SDK builds the same request for you. Open up the SDK call and the same post, the same headers, and the same body are inside. What an SDK does add is convenience. The Open AI SDK turns status codes into named errors you can catch, authentication rate limit, and the rest. Handy, but that is convenience, not capability. For calling Muse Spark, Meta's docs point you to the Open AI and anthropic SDKs. No custom client to learn. Andrew reads that as by design. The takeaway, the API is the SDK. One last thing, versions, paths, and messages change. Everything here was read from Meta's own docs on October 7th, 2026. Check them before you ship.

Recap

[6:02] Let's recap with Claude. A call needs a key and address and a model name, and the key stays out of your code. The Open AI base URL ends in /v1, while the anthropic base is just the host. You can call muse with a raw web request. The open AI SDK or the anthropic SDK. Instructions go in a developer message or an anthropic separate system field. Errors come back as JS. Read the message. Fix the 400s and retry the temporary ones and the judgment this lecture lands on. Plain requests are enough and an SDK adds convenience. Your

Your Turn

[6:33] Turn. Paste this into Claude. Write the smallest Python script that sends one question to Meta's Muse Spark through the open AI SDK. Read my key from an environment variable never from the file itself. Tell me which base URL and model name you used and explain what an HTTP 4001 and an HTTP 4004 from this API mean. Then check two things yourself. Does the script read the key from the environment? And does the base URL it used match the one in Meta's docs? Musing code at Nick Bear Brown.

More from @NikBearBrown

Nik Bear Brown Poet and Songwriter