> ## Documentation Index
> Fetch the complete documentation index at: https://docs.budgetpixel.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Stock Music

> Search BudgetPixel's free background music library from your code or AI agent — reviewed, AI-generated instrumental tracks under CC BY 4.0. Available on every plan, including Free.

The stock music search gives programmatic access to the tracks at
[budgetpixel.com/background-music](https://budgetpixel.com/background-music): AI-generated
instrumental beds for videos, podcasts, streams and apps, in styles such as lofi, corporate,
cinematic, acoustic and electronic. Every track is listened to and scored before it is
listed. Tracks run up to about a minute. Each result comes with the audio file, its length
and a ready-made credit line.

```
GET https://api.budgetpixel.com/v1/stock/music
```

<Note>
  Available on **every plan, including Free**. The stock searches ([images](/stock-images),
  [sound effects](/stock-sound-effects) and music) are the only endpoints a Free plan's API
  key can call. Everything else in the API, and generation through the MCP connector, needs
  a paid plan.
</Note>

## Pricing

* **10 credits per search**, from your plan's credits.
* A search is charged when it succeeds, **including one that matches nothing**.
* Invalid parameters are refused with a `400` and cost nothing.
* Searches count toward the monthly spend limit you can set under
  [Billing](https://budgetpixel.com/developers?tab=billing).

The endpoint searches existing tracks only; it never generates one. To make a track to
order (a set length, lyrics, or a soundtrack for a video), use the
[music generation endpoints](/concepts/models) (paid plans).

## Licence and credit

Every track is licensed [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/): you can
use it commercially, edit it, and use it in client work, provided you credit it where it
is used. Each result includes the credit line, so you don't have to compose one:

* `attribution.text`, for video descriptions, credits, show notes and README files.
* `attribution.html`, for web pages. It links the track, BudgetPixel and the licence.

## Search

<CodeGroup>
  ```bash curl theme={null}
  curl "https://api.budgetpixel.com/v1/stock/music?query=lofi+study&min_duration=30&limit=5" \
    -H "Authorization: Bearer $BUDGETPIXEL_API_KEY"
  ```

  ```python Python theme={null}
  import os, requests

  r = requests.get(
      "https://api.budgetpixel.com/v1/stock/music",
      headers={"Authorization": f"Bearer {os.environ['BUDGETPIXEL_API_KEY']}"},
      params={"query": "lofi study", "min_duration": 30, "limit": 5},
      timeout=30,
  )
  r.raise_for_status()
  for track in r.json()["data"]:
      print(track["title"], track["duration_seconds"], track["urls"]["original"])
      print("  credit:", track["attribution"]["text"])
  ```

  ```javascript Node.js theme={null}
  const params = new URLSearchParams({ query: "lofi study", min_duration: "30", limit: "5" });
  const res = await fetch(`https://api.budgetpixel.com/v1/stock/music?${params}`, {
    headers: { Authorization: `Bearer ${process.env.BUDGETPIXEL_API_KEY}` },
  });
  const { data } = await res.json();
  for (const track of data) console.log(track.title, track.urls.original, track.attribution.text);
  ```
</CodeGroup>

### Parameters

All parameters are optional. Send a `query` to search, or none to browse.

| Parameter | Values | What it does |
| - | - | - |
| `query` | Up to 200 characters | The genre, mood or use, in a few plain words. |
| `min_duration` | Seconds, above 0 | Shortest track to return. |
| `max_duration` | Seconds, above 0 | Longest track to return. |
| `sort` | `popular` (default), `newest`, `top` | With a query, `popular` puts the best matches first. `top` is highest rated. |
| `limit` | 1–20, default 20 | Results per page. The price is the same for any limit. |
| `offset` | 0–5000, default 0 | Results to skip. Fetch the next page with `offset + limit`; each page is a new search. |

Music has no `category` filter. Put the genre in `query`.

### How the search matches

Write the query as a genre, a mood or a use: `lofi study`, `upbeat corporate`,
`dark true crime documentary`, `podcast intro`.

* **Every word counts.** A result must carry most of what you asked for. Filler words
  (`the`, `for`, `background music`) are ignored.
* **Rare words weigh more.** In `calm ukulele`, `ukulele` decides the results.
* **Word forms match.** `uplifting` finds `uplift`.
* **A word the library does not have counts as a miss.**
* **Results that match more of your words come first**, then the more popular.

A long brief, such as a prompt written for a music generator, returns the tracks it names
or nothing. A few words work better. For an exact length, set `min_duration` and
`max_duration` rather than writing the length in the query.

### Response

```json theme={null}
{
  "object": "list",
  "data": [
    {
      "id": "25039d6d-40e2-4e39-bb7b-c792accca0cf",
      "type": "music",
      "title": "Cozy Tape Hiss Study Lofi",
      "tags": ["lofi", "cozy", "slow", "warm", "piano"],
      "keywords": ["lofi study beat", "cozy lofi background", "study lofi guitar", "soft lofi tape hiss", "chill lofi work mix"],
      "category": "music",
      "duration_seconds": 45.07,
      "format": "mp3",
      "sample_rate": 44100,
      "channels": 2,
      "size_bytes": 1805725,
      "page_url": "https://budgetpixel.com/background-music/cozy-tape-hiss-study-lofi-25039d6d",
      "urls": {
        "original": "https://cdn.budgetpixel.com/audio-library/music/lofi-cozy-slow-warm-piano-p3o71s.mp3",
        "cover": "https://cdn.budgetpixel.com/audio-library/art/25039d6d-40e2-4e39-bb7b-c792accca0cf.webp"
      },
      "license": { "code": "CC-BY-4.0", "name": "CC BY 4.0", "url": "https://creativecommons.org/licenses/by/4.0/" },
      "attribution": {
        "required": true,
        "text": "“Cozy Tape Hiss Study Lofi” by BudgetPixel AI (https://budgetpixel.com/background-music/cozy-tape-hiss-study-lofi-25039d6d) — CC BY 4.0",
        "html": "<a href=\"https://budgetpixel.com/background-music/cozy-tape-hiss-study-lofi-25039d6d\">Cozy Tape Hiss Study Lofi</a> by <a href=\"https://budgetpixel.com\">BudgetPixel AI</a>, <a href=\"https://creativecommons.org/licenses/by/4.0/\">CC BY 4.0</a>"
      },
      "ai_generated": true,
      "model": "sonilo-music",
      "prompt": "lofi study beat, soft tape hiss, gentle guitar plucks, slow and cozy",
      "downloads": 273,
      "quality_score": 8,
      "created_at": "2026-08-24T17:28:00Z"
    }
  ],
  "total": 32,
  "limit": 5,
  "offset": 0,
  "has_more": true,
  "credits_charged": 10
}
```

The example shows the first of the five results. `urls.original` is the audio file and
`format` says whether it is WAV or MP3. Most tracks are WAV, which is about 10 MB a minute;
`size_bytes` gives the exact size before you download. `urls.cover` is square cover art.

## From an AI agent (MCP)

The [MCP connector](/mcp-server) has the same search as the `search_stock_audio` tool
(with `kind` set to `music`). Sign in once, with no API key, and ask in plain words:

* *"Find free lofi background music for a study video, at least 30 seconds, with the credit line"*
* *"I need an upbeat corporate track for a product demo"*

The tool costs the same 10 credits per search and works on every plan, including Free.

## Errors

| Status | `code` | Meaning |
| - | - | - |
| 400 | `invalid_parameter` | A parameter is out of range or not an allowed value. The message says what is allowed. Not charged. |
| 401 | `missing_api_key` / `invalid_api_key` | No key, or an unknown or revoked key. |
| 402 | `insufficient_credits` | Your balance is under 10 credits. [Get more credits](https://budgetpixel.com/pricing). |
| 429 | `rate_limited` | More than 60 sound effect and music searches a minute on the account, or the general [rate limits](/concepts/rate-limits). |
| 429 | `monthly_spend_limit_reached` | The monthly spend limit you set has been reached. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.