Muse Spark 1.1
Text Generation • Meta
meta/muse-spark-1.1
- Third-party
Muse Spark 1.1 is Meta's agentic and coding model for multi-step tool loops, software engineering assistants, and long-context reasoning.
| Model Info | |
|---|---|
| More information | link ↗ |
| Request formats | Responses |
| Pricing | <ul><li>Input (per 1M tokens)$1.25</li><li>Cached input (per 1M tokens)$0.16</li><li>Output (per 1M tokens)$4.25</li></ul> |
Usage
const response = await env.AI.run(
'meta/muse-spark-1.1',
{
messages: [
{
role: 'system',
content:
'You are a pragmatic senior JavaScript reviewer. Prefer small, production-safe fixes and explain the root cause before the patch.',
},
{
role: 'user',
content:
'Review this function:\n\nasync function processOnce(queue) {\n if (queue.length === 0) return;\n const item = queue.shift();\n await save(item);\n if (queue.length > 0) processOnce(queue);\n}\n\nTwo requests can call processOnce(queue) at the same time. What can go wrong, and how would you fix it without changing the save() function? Include a concise corrected implementation.',
},
],
max_completion_tokens: 4096,
},
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "meta/muse-spark-1.1",
"input": {
"messages": [
{
"role": "system",
"content": "You are a pragmatic senior JavaScript reviewer. Prefer small, production-safe fixes and explain the root cause before the patch."
},
{
"role": "user",
"content": "Review this function:\n\nasync function processOnce(queue) {\n if (queue.length === 0) return;\n const item = queue.shift();\n await save(item);\n if (queue.length > 0) processOnce(queue);\n}\n\nTwo requests can call processOnce(queue) at the same time. What can go wrong, and how would you fix it without changing the save() function? Include a concise corrected implementation."
}
],
"max_completion_tokens": 4096
}
}'
This is a concurrent drain + fire-and-forget bug.
### Root cause
JS is single-threaded, but `await` yields to the event loop. You have shared mutable state `queue` with no mutual exclusion.
If A and B call `processOnce(queue)` at the same time:
1. A: `queue.length > 0` -> true
2. A: `shift()` -> item1, `await save(item1)` -> **yields**
3. B: `queue.length > 0` -> still true, `shift()` -> item2, `await save(item2)` -> **now `save()` is running in parallel**. If `save()` must be serial / order dependent, you break it. `shift()` can also return `undefined` if B empties it first.
4. `if(queue.length > 0) processOnce(queue)` is **not awaited**. Caller resolves early, queue is still draining. Rejections are lost and caller thinks it's done.
### Fix
Serialize draining. One drain loop at a time, `while` not recursion, and piggyback concurrent callers onto the same promise + re-check for items enqueued in the gap.
Don't change `save()`. Just guard it:
```js
let drainPromise = null;
async function processOnce(queue) {
if (drainPromise) return drainPromise;
drainPromise = (async () => {
while (queue.length > 0) {
const item = queue.shift();
await save(item);
}
})().finally(() => {
drainPromise = null;
// items pushed between last shift() and clearing the flag
if (queue.length > 0) return processOnce(queue);
});
return drainPromise;
}
```
What this changes:
* `drainPromise` lock prevents 2 concurrent drain loops.
* `while` loop + `await save()` guarantees serial saves.
* Concurrent callers return the same promise, so they properly await completion.
* `finally` re-check prevents losing items enqueued right after the loop ends.
{
"id": "resp_6ac7afe7b1edff27f7904b24",
"object": "response",
"created_at": 1791471590,
"model": "muse-spark-1.1",
"output": [
{
"type": "reasoning",
"id": "rs_6ac7afe7b1edff27f7904b24:rs_d69dde63-919d-49f4-9c17-65b594289afb",
"summary": [],
"status": "completed"
},
{
"type": "message",
"id": "msg_ce37fe35-31f4-4a9c-aea7-3f2ee96186e5",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "This is a concurrent drain + fire-and-forget bug.\n\n### Root cause\n\nJS is single-threaded, but `await` yields to the event loop. You have shared mutable state `queue` with no mutual exclusion.\n\nIf A and B call `processOnce(queue)` at the same time:\n\n1. A: `queue.length > 0` -> true\n2. A: `shift()` -> item1, `await save(item1)` -> **yields**\n3. B: `queue.length > 0` -> still true, `shift()` -> item2, `await save(item2)` -> **now `save()` is running in parallel**. If `save()` must be serial / order dependent, you break it. `shift()` can also return `undefined` if B empties it first.\n4. `if(queue.length > 0) processOnce(queue)` is **not awaited**. Caller resolves early, queue is still draining. Rejections are lost and caller thinks it's done.\n\n### Fix\n\nSerialize draining. One drain loop at a time, `while` not recursion, and piggyback concurrent callers onto the same promise + re-check for items enqueued in the gap.\n\nDon't change `save()`. Just guard it:\n\n```js\nlet drainPromise = null;\n\nasync function processOnce(queue) {\n if (drainPromise) return drainPromise;\n\n drainPromise = (async () => {\n while (queue.length > 0) {\n const item = queue.shift();\n await save(item);\n }\n })().finally(() => {\n drainPromise = null;\n // items pushed between last shift() and clearing the flag\n if (queue.length > 0) return processOnce(queue);\n });\n\n return drainPromise;\n}\n```\n\nWhat this changes:\n\n* `drainPromise` lock prevents 2 concurrent drain loops.\n* `while` loop + `await save()` guarantees serial saves.\n* Concurrent callers return the same promise, so they properly await completion.\n* `finally` re-check prevents losing items enqueued right after the loop ends.",
"annotations": [],
"logprobs": []
}
],
"status": "completed"
}
],
"status": "completed",
"usage": {
"input_tokens": 134,
"output_tokens": 2852,
"total_tokens": 2986,
"input_tokens_details": {
"cached_tokens": 113
},
"output_tokens_details": {
"reasoning_tokens": 2409
}
},
"top_logprobs": 0,
"temperature": 1,
"top_p": 1,
"service_tier": "auto",
"reasoning": {
"effort": "high"
},
"background": false,
"tools": [],
"tool_choice": "auto",
"truncation": "disabled",
"completed_at": 1791471591,
"error": null,
"incomplete_details": null,
"instructions": null,
"parallel_tool_calls": true,
"store": true,
"max_output_tokens": 4096
}
Examples
<details>
<summary>SQL Correctness Review — Review a SQL query for correctness and performance, then propose a safer replacement.</summary>
const response = await env.AI.run(
'meta/muse-spark-1.1',
{
messages: [
{
role: 'system',
content:
'You are a database engineer. Be precise about semantics, indexes, and concurrency. Do not assume schema details that are not provided.',
},
{
role: 'user',
content:
"A payments table has columns id, account_id, status, amount_cents, created_at, and settled_at. Review this query used to calculate an account's settled balance: SELECT SUM(amount_cents) FROM payments WHERE account_id = ? AND status = 'settled' OR status = 'refunded' AND created_at >= ?; Identify the correctness bug, give the corrected query, and suggest one useful index. Keep the answer under 400 words.",
},
],
max_completion_tokens: 4096,
},
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "meta/muse-spark-1.1",
"input": {
"messages": [
{
"role": "system",
"content": "You are a database engineer. Be precise about semantics, indexes, and concurrency. Do not assume schema details that are not provided."
},
{
"role": "user",
"content": "A payments table has columns id, account_id, status, amount_cents, created_at, and settled_at. Review this query used to calculate an account'\''s settled balance: SELECT SUM(amount_cents) FROM payments WHERE account_id = ? AND status = '\''settled'\'' OR status = '\''refunded'\'' AND created_at >= ?; Identify the correctness bug, give the corrected query, and suggest one useful index. Keep the answer under 400 words."
}
],
"max_completion_tokens": 4096
}
}'
Operator precedence bug. `AND` binds tighter than `OR`, so your query is parsed as:
```sql
(account_id = ? AND status = 'settled')
OR
(status = 'refunded' AND created_at >= ?)
```
Failures:
1. Leaks data across accounts - all `refunded` rows for any account after `?` are summed into this account.
2. Drops the `created_at` filter for `settled` rows, and drops `account_id` filter for `refunded`.
### Corrected query
If you intend to filter both statuses by date:
```sql
SELECT COALESCE(SUM(amount_cents),0) FROM payments
WHERE account_id = ?
AND status IN ('settled','refunded')
AND created_at >= ?;
```
If you intended date filter only for refunded:
```sql
SELECT COALESCE(SUM(amount_cents),0) FROM payments
WHERE account_id = ?
AND (status = 'settled' OR (status = 'refunded' AND created_at >= ?));
```
Note: For a *settled* balance, you likely want `settled_at >= ?`, not `created_at`.
### Index
Composite to support equality on `account_id`, equality/IN on `status`, range on `created_at`, covering `amount_cents`:
```sql
CREATE INDEX idx_payments_acct_status_created
ON payments (account_id, status, created_at) INCLUDE (amount_cents);
```
This allows an index-only scan per account without touching the heap.
{
"id": "resp_6ac7aff0b2536166015f4c31",
"object": "response",
"created_at": 1791471600,
"model": "muse-spark-1.1",
"output": [
{
"type": "reasoning",
"id": "rs_6ac7aff0b2536166015f4c31:rs_bd77c866-9452-4cf2-84d6-3052aa3f613f",
"summary": [],
"status": "completed"
},
{
"type": "message",
"id": "msg_58de9d22-820f-49a1-aecd-ff8c43ae16a3",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "Operator precedence bug. `AND` binds tighter than `OR`, so your query is parsed as:\n\n```sql\n(account_id = ? AND status = 'settled')\nOR \n(status = 'refunded' AND created_at >= ?)\n```\n\nFailures:\n1. Leaks data across accounts - all `refunded` rows for any account after `?` are summed into this account.\n2. Drops the `created_at` filter for `settled` rows, and drops `account_id` filter for `refunded`.\n\n### Corrected query\n\nIf you intend to filter both statuses by date:\n\n```sql\nSELECT COALESCE(SUM(amount_cents),0) FROM payments\nWHERE account_id = ?\n AND status IN ('settled','refunded')\n AND created_at >= ?;\n```\n\nIf you intended date filter only for refunded:\n\n```sql\nSELECT COALESCE(SUM(amount_cents),0) FROM payments\nWHERE account_id = ?\n AND (status = 'settled' OR (status = 'refunded' AND created_at >= ?));\n```\n\nNote: For a *settled* balance, you likely want `settled_at >= ?`, not `created_at`.\n\n### Index\n\nComposite to support equality on `account_id`, equality/IN on `status`, range on `created_at`, covering `amount_cents`:\n\n```sql\nCREATE INDEX idx_payments_acct_status_created \nON payments (account_id, status, created_at) INCLUDE (amount_cents);\n```\n\nThis allows an index-only scan per account without touching the heap.",
"annotations": [],
"logprobs": []
}
],
"status": "completed"
}
],
"status": "completed",
"usage": {
"input_tokens": 143,
"output_tokens": 1578,
"total_tokens": 1721,
"input_tokens_details": {
"cached_tokens": 113
},
"output_tokens_details": {
"reasoning_tokens": 1249
}
},
"top_logprobs": 0,
"temperature": 1,
"top_p": 1,
"service_tier": "auto",
"reasoning": {
"effort": "high"
},
"background": false,
"tools": [],
"tool_choice": "auto",
"truncation": "disabled",
"completed_at": 1791471600,
"error": null,
"incomplete_details": null,
"instructions": null,
"parallel_tool_calls": true,
"store": true,
"max_output_tokens": 4096
}
</details>
<details>
<summary>TypeScript Utility Refactor — Turn an unreliable JavaScript helper into a typed, testable implementation with explicit edge-case behavior.</summary>
const response = await env.AI.run(
'meta/muse-spark-1.1',
{
messages: [
{
role: 'system',
content:
'You are a TypeScript library maintainer. Prefer small APIs, explicit types, and tests that document behavior.',
},
{
role: 'user',
content:
'Refactor this helper into TypeScript:\n\nfunction groupBy(items, key) {\n return items.reduce((out, item) => {\n (out[item[key]] ||= []).push(item);\n return out;\n }, {});\n}\n\nProvide a generic type-safe version and three focused tests covering an empty input, a missing key value, and two items sharing a key. State your chosen behavior for missing keys.',
},
],
max_completion_tokens: 4096,
},
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "meta/muse-spark-1.1",
"input": {
"messages": [
{
"role": "system",
"content": "You are a TypeScript library maintainer. Prefer small APIs, explicit types, and tests that document behavior."
},
{
"role": "user",
"content": "Refactor this helper into TypeScript:\n\nfunction groupBy(items, key) {\n return items.reduce((out, item) => {\n (out[item[key]] ||= []).push(item);\n return out;\n }, {});\n}\n\nProvide a generic type-safe version and three focused tests covering an empty input, a missing key value, and two items sharing a key. State your chosen behavior for missing keys."
}
],
"max_completion_tokens": 4096
}
}'
