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

# Cancel response

> Cancel a background response

Use this endpoint for responses stored by OpenAI models with `store: true` or `background: true`. The request must come from the workspace that created the response. See [stored responses](https://docs.inworld.ai/router/responses.md#stored-responses-and-continuation).

## API reference

**Endpoint:** `POST https://api.inworld.ai/v1/responses/{response_id}/cancel`

### Authorization

- `Authorization` (string; required) — Your [authentication](../../../api-reference/introduction) credentials. For Basic authentication, please populate `Basic $INWORLD_API_KEY`.
  
  Please make sure your API Key has [write permissions for the Router API](https://docs.inworld.ai/api-reference/introduction.md#getting-an-api-key) in order to create, update, and delete routers. You can create a key in one command with the [Inworld CLI](../../../developer-tools/inworld-cli): `inworld workspace add-key`.

### Path parameters

- `response_id` (string; required) — The id of a response stored by an OpenAI model (`store: true` or `background: true`).

### Response

Status: `200`. Content type: `application/json`.

- `id` (string)
- `object` (string)
- `created_at` (integer)
- `status` (enum<string>; options: "completed", "failed", "in_progress", "queued", "cancelled", "incomplete")
- `model` (string) — The model id the provider reports, for example `gpt-5.4`. The provider-qualified id is in `routing.attempts[].model`.
- `output` (object[]) — Output items: `message`, `reasoning`, `function_call`, and hosted tool items.
- `usage` (object)
  - `input_tokens` (integer)
  - `output_tokens` (integer)
  - `total_tokens` (integer)
  - `input_tokens_details` (object)
  - `output_tokens_details` (object)
- `error` (object)
- `incomplete_details` (object)
- `routing` (object) — Inworld routing information. Present on responses from `POST /v1/responses`, not on retrieved responses.
  - `attempts` (object[])
    - `model` (string) — The model identifier that was attempted.
    - `success` (boolean) — Whether this attempt succeeded.
    - `time_to_first_token_ms` (integer) — Time to receive the first token in milliseconds.
    - `status_code` (integer) — HTTP status of a failed attempt.
    - `error` (string) — Why the attempt failed.
    - `duration_ms` (number) — Duration of the attempt in milliseconds.
    - `warnings` (string[]) — Notes about the attempt, for example parameters skipped because the model does not support them.
  - `generation_id` (string)
  - `route_id` (string) — The saved router's route that was chosen, when `model` is a saved router.
  - `variant_id` (string) — The saved router's variant that was chosen, when `model` is a saved router.
  - `total_duration_ms` (integer)

### Response examples

#### 200: default_response

```json
{
  "id": "string",
  "object": "response",
  "created_at": 0,
  "status": "completed",
  "model": "string",
  "output": [],
  "usage": {
    "input_tokens": 0,
    "output_tokens": 0,
    "total_tokens": 0
  },
  "routing": {
    "attempts": [
      {
        "model": "string",
        "success": true,
        "time_to_first_token_ms": 0,
        "status_code": 0,
        "error": "string",
        "duration_ms": 0,
        "warnings": [
          "string"
        ]
      }
    ],
    "generation_id": "string",
    "route_id": "string",
    "variant_id": "string",
    "total_duration_ms": 0
  }
}
```

#### 400: default_response

```json
{
  "error": {
    "message": "'model' field is required",
    "type": "invalid_request_error",
    "code": "string",
    "param": "string"
  }
}
```

#### 401: default_response

```json
{
  "error": {
    "message": "'model' field is required",
    "type": "invalid_request_error",
    "code": "string",
    "param": "string"
  }
}
```

#### 404: default_response

```json
{
  "error": {
    "message": "'model' field is required",
    "type": "invalid_request_error",
    "code": "string",
    "param": "string"
  }
}
```

#### 503: default_response

```json
{
  "error": {
    "message": "'model' field is required",
    "type": "invalid_request_error",
    "code": "string",
    "param": "string"
  }
}
```

### Code examples

#### cURL

```bash
curl -X POST 'https://api.inworld.ai/v1/responses/resp_68af2c1e9f5c8190a0b6d1a0c4e5f6a7/cancel' \
  -H "Authorization: Basic $INWORLD_API_KEY"
```

#### Python

```python
import requests

url = "https://api.inworld.ai/v1/responses/%7Bresponse_id%7D/cancel"
headers = {
  "Authorization": "<api_key>"
}

response = requests.request("POST", url, headers=headers)

print(response.text)
```

#### JavaScript

```javascript
const options = {method: 'POST', headers: {"Authorization":"<api_key>"}};

fetch('https://api.inworld.ai/v1/responses/%7Bresponse_id%7D/cancel', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));
```

#### Python (OpenAI SDK)

```python
import os
from openai import OpenAI

api_key = os.environ["INWORLD_API_KEY"]
client = OpenAI(
    base_url="https://api.inworld.ai/v1",
    api_key=api_key,
    default_headers={"Authorization": f"Basic {api_key}"},
)

response = client.responses.cancel("resp_68af2c1e9f5c8190a0b6d1a0c4e5f6a7")
print(response.status)
```
