RockBlocks Beat API

Turn your app’s words or code into a real drum beat. Send text and get TextyBeat’s groove — one beat per sentence — or send Python, JavaScript or SQL and get RockCode’s — one beat per block. You get the beat as JSON, a picture to show, a widget that plays it, and an Open in RockBlocks link that drops it straight into the drum machine. Free, no key, no sign-up. The same input always makes the same beat.

Try it

Text, as a playable widget:

Code, as a picture linked to RockBlocks:

RockCode beat for a short Python program

The endpoints

GET or POST /api/v1/beat
The beats as JSON, with openUrl, imageUrl, embedUrl and a ready-to-paste embedHtml.
GET or POST /api/v1/beat/image
The same beats drawn as an SVG — use the URL as an image.
/embed/beat?…
A widget for an <iframe>: shows the beat, plays it, and opens it in RockBlocks in a new tab.

All three take the same parameters — as a query string, or for POST as JSON (or form fields, or a plain-text body that is the input). CORS is open, so you can call it straight from a browser. Each IP address can make up to 120 requests a minute across the API, picture and widget — past that you’ll get a 429 for the rest of the minute. The same input always makes the same beat, so cache what you get back.

modetext (TextyBeat — one beat per sentence) or code (RockCode — one beat per block of code). Defaults to text.
inputThe text or code. Up to 280 characters of text or 2000 of code are used (the response says "truncated": trueif yours was longer). At most 4 beats come back, for RockBlocks’ Slots A–D. text or code work as the name too.
languageCode mode only: python, javascript, sql. Defaults to python.
kitDrum kit: Acoustic, 808, 909, Fart, Cats, Techno, Latin, Metal, Reggaeton, Middle Eastern, Birds. Defaults to Acoustic.
bpmTempo, 40–240. Leave it out for TextyBeat’s 100 bpm, or each RockCode block’s own tempo.

From JavaScript

const res = await fetch("https://rockblocks.app/api/v1/beat", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ mode: "code", language: "javascript", input: myCode }),
});
const beat = await res.json();

img.src = beat.imageUrl;          // a picture of the beat
link.href = beat.openUrl;         // "Open in RockBlocks" (use target="_blank")
container.innerHTML = beat.embedHtml; // or a playable widget

No code: a picture or a widget

<a href="OPEN_URL" target="_blank" rel="noopener">
  <img src="https://rockblocks.app/api/v1/beat/image?mode=text&input=Hello%20world." alt="My beat">
</a>
<iframe
  src="https://rockblocks.app/embed/beat?mode=code&language=sql&input=SELECT%20name%20FROM%20users%20WHERE%20age%20%3E%2021"
  width="100%" height="220" style="border:0;border-radius:12px" title="RockBlocks beat"></iframe>

The response

Each beat has its source sentence or code block, tempo and time signature, and one entry per drum. Each beat-block on a drum has its RockBlocks tile id and its hits spelled out — at and length in beats — so you can draw or play it yourself. Errors come back as { "error": "…" } with status 400 (bad parameters) or 422 (no beat in that input).

{
  "mode": "text",
  "kit": "Acoustic",
  "truncated": false,
  "beats": [
    {
      "slot": "A",
      "source": "Every app has a beat.",
      "bpm": 100,
      "beats": 6,
      "timeSignature": "6/4",
      "lines": [
        {
          "instrument": "hihatOpen",
          "name": "Hi-Hat (Open)",
          "color": "#047857",
          "volume": 100,
          "blocks": [
            null,
            null,
            {
              "tile": "n-quarter",
              "label": "Quarter",
              "hits": [
                {
                  "at": 0,
                  "length": 1
                }
              ]
            },
            null,
            null,
            null
          ]
        }
      ]
    },
    "…"
  ],
  "openUrl": "https://rockblocks.app/import#W3siYnBtIjoxMDAsImxpbmVzIjpbey…",
  "imageUrl": "https://rockblocks.app/api/v1/beat/image?mode=text&input=Every+app+has…",
  "embedUrl": "https://rockblocks.app/embed/beat?mode=text&input=Every+app+has+a+beat…",
  "embedHtml": "<iframe src=\"…\" …></iframe>"
}

How Open in RockBlocks works

openUrl carries the beats in the link’s #fragment, which browsers never send to a server. Opening it puts them in the visitor’s own RockBlocks Slots A–D (in empty slots where it can) and opens the drum machine, where they can remix it, add a bass line, and save it. Open it in a new tab — target="_blank" — so your app stays where it was.