# End a speech session

URL: https://www.atmee.ai/docs/v2/api/reference/speech-sessions/endSpeechSession

`POST /v1/speech_sessions/{session_id}/end`

Ends the session (`completed`, `endReason: ended_by_api`). With no
connection open it settles now. With a connection open, the session
ends at its next usage report (within 30 s) and is billed until
then: the answer is `status: active` with `endRequestedAt` set, and
`GET` reads it `completed` once it settled. **Idempotent**: a repeat
keeps the first request; ending a settled session answers
`alreadyEnded: true`.

## Parameters

| Name | In | Required | Description |
| --- | --- | --- | --- |
| `session_id` | path | yes | The speech session's id, as `POST /v1/speech_sessions` returned it. |

## Responses

| Status | Description | Schema |
| --- | --- | --- |
| `200` | The session is ended or its end is requested (or it already was ended). | `SpeechSessionEndResponse` |
| `400` | Both `X-Api-Key` and `Authorization` sent where the deployment accepts user tokens; send one. | none |
| `401` | Missing or invalid API key -- or a user token that is invalid, anonymous, or of a user who may act for no account (invalid_login) | none |
| `403` | `forbidden` — the session belongs to another account \| `avatar_not_allowed` — the session is not on this key's avatar \| `insufficient_scope` — the API key lacks the `sessions` scope \| account_not_allowed | `ApiErrorResponse` |
| `404` | `not_found` — no such speech session | `ApiErrorResponse` |
| `409` | account_ambiguous -- a user token of a user who may act for several accounts, without an `X-Account-Id` header naming one. | `ApiErrorResponse` |
| `500` | `finalize_failed` — the session could not be settled; retry | `ApiErrorResponse` |
| `503` | `speech_unavailable` — speech sessions are not configured on this deployment | `ApiErrorResponse` |

## `200` response fields

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `sessionId` | string | yes |  |
| `status` | string (`active`, `completed`, `failed`) | yes | `active` when a connection is open: the end is requested (`endRequestedAt`) and settles at its next usage report. |
| `alreadyEnded` | boolean | yes | True when the session was settled before this call. |
| `endRequestedAt` | string | no | When the end was first requested, while a connection is open; null once settled at this call or before. |
| `endedAt` | string | no |  |
| `endReason` | string | no |  |
