# End a focus session

Gracefully end a focus session. No new segments are generated, but already-ready segments stay playable. The operation is idempotent.

Ending a session you do not own returns `404`. Ending an already-ended session is a no-op and returns the session's current state.

## Path parameters

**`organization_id`** string required

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

**`session_id`** string required

The focus session id (`mfocus_`-prefixed).

## Returns

The focus session object with `status` set to `ended` (or `stopped_cap`). The shape matches [Get a focus session](/docs/api-reference/music/get-focus-session): `session_id`, `status`, `goal`, `engine`, `target_minutes`, `total_segments`, `ready_count`, `segments`, `more_pending`, and `next_ready_at`.

Example

```bash cURL
curl -X POST "https://api.aitronos.com/v1/music/org_abc123/focus/sessions/mfocus_7c2a9f4e1b8d/end" \
  -H "X-API-Key: $FREDDY_API_KEY"
```


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

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

session = client.post("/v1/music/org_abc123/focus/sessions/mfocus_7c2a9f4e1b8d/end")
print(session["status"])
```


```python Python
import os
import requests

api_key = os.environ["FREDDY_API_KEY"]

response = requests.post(
    "https://api.aitronos.com/v1/music/org_abc123/focus/sessions/mfocus_7c2a9f4e1b8d/end",
    headers={"X-API-Key": api_key},
)
print(response.json()["status"])
```


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

const response = await fetch(
  'https://api.aitronos.com/v1/music/org_abc123/focus/sessions/mfocus_7c2a9f4e1b8d/end',
  { method: 'POST', headers: { 'X-API-Key': apiKey } }
);

const session = await response.json();
console.log(session.status);
```

**Response:**


```json 200 OK
{
  "session_id": "mfocus_7c2a9f4e1b8d",
  "status": "ended",
  "goal": "focus",
  "engine": "studio",
  "target_minutes": 60,
  "total_segments": 30,
  "ready_count": 5,
  "segments": [],
  "more_pending": false,
  "next_ready_at": null
}
```

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": "Focus session not found",
    "type": "client_error",
    "status": 404,
    "details": { "session_id": "mfocus_7c2a9f4e1b8d" },
    "trace_id": "req_jkl012mno",
    "timestamp": "2026-06-28T10:30:00Z"
  }
}
```

## Related Resources

- [Start a focus session](/docs/api-reference/music/start-focus-session)
- [Get a focus session](/docs/api-reference/music/get-focus-session)
- [Promote a focus segment](/docs/api-reference/music/promote-focus-segment)