# Share a track

Create a public share link for a track. Returns `201 Created` with the share record, including the raw token shown **once**. Only the track's creator may share it.

The raw `token` and its `url` are returned only on creation — only a hash is stored, so the token cannot be retrieved later. A non-owner receives `404`. The request body is optional; defaults apply when omitted.

## Path parameters

**`organization_id`** string required

The organization the track is scoped to. The caller must belong to it.

**`track_id`** string required

The track id to share (`mtrack_`-prefixed).

## Request Body

**`visibility`** string optional · Defaults to `link_only`

Share visibility. One of `link_only` (only people with the link can open it) or `public`.

**`expires_in_days`** integer optional

Number of days until the link expires (minimum `1`). Values above `90` are clamped to `90`. Omit for a link that never expires.

## Returns

A share link object.

**`id`** string · Share link id (`mslink_`-prefixed).

**`token`** string · The raw share token. Shown only once — only its hash is stored.

**`url`** string · Public URL that opens the share without signing in.

**`target_type`** string · `track`.

**`visibility`** string · `link_only` or `public`.

**`expires_at`** string · When the link expires (UTC), or `null` for never.

**`created_at`** string · When the link was created (UTC).

Example

```bash cURL
curl -X POST "https://api.aitronos.com/v1/music/org_abc123/tracks/mtrack_b4d9e1c6a72f/share" \
  -H "X-API-Key: $FREDDY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "visibility": "link_only", "expires_in_days": 30 }'
```


```python Python SDK
from aitronos import Aitronos  # pip install aitronos-sdk

client = Aitronos(api_key="your-api-key")

share = client.post(
    "/v1/music/org_abc123/tracks/mtrack_b4d9e1c6a72f/share",
    json={"visibility": "link_only", "expires_in_days": 30},
)
print(share["url"])
```


```python Python
import os
import requests

api_key = os.environ["FREDDY_API_KEY"]

response = requests.post(
    "https://api.aitronos.com/v1/music/org_abc123/tracks/mtrack_b4d9e1c6a72f/share",
    headers={"X-API-Key": api_key},
    json={"visibility": "link_only", "expires_in_days": 30},
)
print(response.json()["url"])
```


```javascript JavaScript
const apiKey = process.env.FREDDY_API_KEY;

const response = await fetch(
  'https://api.aitronos.com/v1/music/org_abc123/tracks/mtrack_b4d9e1c6a72f/share',
  {
    method: 'POST',
    headers: { 'X-API-Key': apiKey, 'Content-Type': 'application/json' },
    body: JSON.stringify({ visibility: 'link_only', expires_in_days: 30 }),
  }
);

const share = await response.json();
console.log(share.url);
```

**Response:**


```json 201 Created
{
  "id": "mslink_3a7f2c9e8b14",
  "token": "shr_9f3a2b7c1e4d6a8f0b2c4d6e8f1a3b5c",
  "url": "https://api.aitronos.com/v1/music/shared/shr_9f3a2b7c1e4d6a8f0b2c4d6e8f1a3b5c",
  "target_type": "track",
  "visibility": "link_only",
  "expires_at": "2026-07-28T10:30:00Z",
  "created_at": "2026-06-28T10:30:00Z"
}
```

Errors

```json 401 Unauthorized
{
  "success": false,
  "error": {
    "code": "AUTHENTICATION_REQUIRED",
    "message": "Authentication required. Please provide a valid API key.",
    "system_message": "Missing or invalid authorization header",
    "type": "authentication_error",
    "status": 401,
    "details": {},
    "trace_id": "req_abc123xyz",
    "timestamp": "2026-06-28T10:30:00Z"
  }
}
```


```json 404 Not Found
{
  "success": false,
  "error": {
    "code": "RESOURCE_NOT_FOUND",
    "message": "The requested resource was not found.",
    "system_message": "Track not found or not owned by caller",
    "type": "client_error",
    "status": 404,
    "details": { "track_id": "mtrack_b4d9e1c6a72f" },
    "trace_id": "req_jkl012mno",
    "timestamp": "2026-06-28T10:30:00Z"
  }
}
```

## Related Resources

- [Share a collection](/docs/api-reference/music/share-collection)
- [Open a shared link](/docs/api-reference/music/resolve-share)
- [Revoke a share link](/docs/api-reference/music/revoke-share)