# Cancel inference run

POST

/v2/workspaces/{workspace\_id}/inferences/{inference\_id}/cancel

```bash
curl --request POST \
  --url https://api.app.layer.ai/api/v2/workspaces/:workspace_id/inferences/:inference_id/cancel \
  --header 'Authorization: Bearer <token>'
```

```python
import requests


url = "https://api.app.layer.ai/api/v2/workspaces/:workspace_id/inferences/:inference_id/cancel"


headers = {"Authorization": "Bearer <token>"}


response = requests.post(url, headers=headers)


print(response.json())
```

```js
const url = 'https://api.app.layer.ai/api/v2/workspaces/:workspace_id/inferences/:inference_id/cancel';
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};


try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main


import (
  "fmt"
  "net/http"
  "io"
)


func main() {


  url := "https://api.app.layer.ai/api/v2/workspaces/:workspace_id/inferences/:inference_id/cancel"


  req, _ := http.NewRequest("POST", url, nil)


  req.Header.Add("Authorization", "Bearer <token>")


  res, _ := http.DefaultClient.Do(req)


  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)


  fmt.Println(res)
  fmt.Println(string(body))


}
```

```php
<?php


$curl = curl_init();


curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.app.layer.ai/api/v2/workspaces/:workspace_id/inferences/:inference_id/cancel",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>"
  ],
]);


$response = curl_exec($curl);
$err = curl_error($curl);


curl_close($curl);


if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

```java
OkHttpClient client = new OkHttpClient();


Request request = new Request.Builder()
  .url("https://api.app.layer.ai/api/v2/workspaces/:workspace_id/inferences/:inference_id/cancel")
  .post(null)
  .addHeader("Authorization", "Bearer <token>")
  .build();


Response response = client.newCall(request).execute();
```

```ruby
require 'uri'
require 'net/http'


url = URI("https://api.app.layer.ai/api/v2/workspaces/:workspace_id/inferences/:inference_id/cancel")


http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true


request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'


response = http.request(request)
puts response.read_body
```

```csharp
var client = new RestClient("https://api.app.layer.ai/api/v2/workspaces/:workspace_id/inferences/:inference_id/cancel");
var request = new RestRequest("", Method.Post);
request.AddHeader("Authorization", "Bearer <token>");
var response = client.Execute(request);
```

* Layer API

> **Unchanged from v1.** This endpoint’s documented request and response schemas are identical in v1 and v2 — change the `/v1` prefix to `/v2`. Schema equality is not a promise about behaviour, so keep your usual smoke tests.

Request cancellation of an in-flight inference. Fire-and-forget: returns immediately after signalling the run to stop. Poll GET /workspaces/{workspace\_id}/inferences/{inference\_id} for the eventual CANCELLED status. A run that already COMPLETED can no longer be cancelled and returns INFERENCE\_ALREADY\_COMPLETE; the other terminal states are idempotent no-ops.

## Authorizations

* **[bearerAuth](/docs/v2/rest-api#bearerauth)**
* **[oauth2](/docs/v2/rest-api#oauth2)**
* **[serviceAccount](/docs/v2/rest-api#serviceaccount)**  
generation:write

## Parameters

### Path Parameters

**workspace\_id**

required

_Workspace Id_

Id of the workspace that owns the resource.

string format: uuid

Id of the workspace that owns the resource.

**inference\_id**

required

_Inference Id_

Id of the generation.

string format: uuid

Id of the generation.

### Header Parameters

**Idempotency-Key**

string

<= 255 characters

Opaque key making a retry of this request return the first result. A 2xx response is replayed for 24 hours with `Idempotent-Replayed: true`. A 4xx releases the key. A 5xx, or a request still running, holds the key for 120 seconds, during which a retry gets 409; after that a retry executes again. The key covers the method, path, query, and byte-identical body it was first used with; reusing it for a different request is rejected with 422\. Protection is best effort: if the key store is unavailable, or a record is lost early, a retry can execute again even after an earlier 409\. See the Idempotency section of the API description.

## Responses

### 202

Successful Response

_GetForgeRunOutput_object

**inference\_id**

required

_Inference Id_

Unique identifier for this forge run.

string format: uuid

**status**

required

_InferenceStatus_

Current status: in\_progress, complete, failed, cancelled, or deleted.

string

Allowed values: in\_progress complete failed cancelled deleted

**poll\_interval\_seconds**

_Poll Interval Seconds_

Suggested polling interval in seconds. Present while IN\_PROGRESS.

integer

nullable

**completed\_at**

_Completed At_

Completion timestamp. Present only on COMPLETE.

string format: date-time

nullable

**outputs**

_Outputs_

Generated assets. Present only on COMPLETE.

Array<object>

nullable

_ForgeRunAsset_object

**file\_id**

required

_File Id_

File ID for the generated asset.

string format: uuid

**url**

required

_Url_

Download URL for the asset.

string

**content\_type**

required

_Content Type_

MIME type, e.g. image/png or video/mp4.

string

**preview\_url**

_Preview Url_

Thumbnail/preview URL.

string

nullable

**width**

_Width_

Width in pixels.

integer

nullable

**height**

_Height_

Height in pixels.

integer

nullable

**duration\_seconds**

_Duration Seconds_

Duration for video/audio assets.

number

nullable

**file\_size\_bytes**

_File Size Bytes_

File size in bytes.

integer

nullable

**metadata**

Any of:

**FileMetadataView**

_FileMetadataView_

What an engine needs beyond the image to build a resource from a file. Each kind is null when absent.

object

**tile**

Any of:

**null**

_TileMetadataView_

Where a game tile’s sprite sits on its grid, in the sprite’s own pixels from its top-left corner.

object

**shape**

required

_TileShape_

The outline of one grid cell seen from straight above.

string

Allowed values: SQUARE HEXAGON

**orientation**

required

_TileOrientation_

How the cell is turned to the camera: DIAMOND or ALIGNED for a square, POINTY\_TOP or FLAT\_TOP for a hexagon.

string

Allowed values: DIAMOND ALIGNED POINTY\_TOP FLAT\_TOP

**elevation**

required

_Elevation_

Camera tilt in degrees above the ground plane; 90 is straight down.

number

**facing**

required

_Facing_

Quarter turn of the camera around the tile, in degrees clockwise seen from above: 0, 90, 180, or 270\. A hexagon is only drawn facing 0.

integer

**footprint\_width**

required

_Footprint Width_

Cells the footprint covers across (the base’s right-hand edge) at facing 0.

integer

**footprint\_depth**

required

_Footprint Depth_

Cells the footprint covers deep (the base’s left-hand edge) at facing 0.

integer

**height**

required

_Height_

Wall height in cell sides: 0 is a flat ground tile, 1 a cube on a square.

number

**tile\_width**

required

_Tile Width_

Width in pixels of one cell’s base outline in the sprite.

integer

**tile\_height**

required

_Tile Height_

Height in pixels of one cell’s base outline in the sprite.

integer

**anchor**

required

_TilePointView_

The point the tile is placed by: the bottom centre of the cell it stands on (the front cell of a footprint wider than one).

object

**x**

required

_X_

Pixels right of the sprite’s left edge.

number

**y**

required

_Y_

Pixels down from the sprite’s top edge.

number

**cell\_center**

required

_TilePointView_

The centre of the anchor’s cell. Godot and Unity pin a tile here rather than at the anchor.

object

**x**

required

_X_

Pixels right of the sprite’s left edge.

number

**y**

required

_Y_

Pixels down from the sprite’s top edge.

number

**base\_outline**

required

_Base Outline_

The footprint’s whole base outline, clockwise on screen from the anchor’s vertex or edge.

Array<object>

_TilePointView_object

**x**

required

_X_

Pixels right of the sprite’s left edge.

number

**y**

required

_Y_

Pixels down from the sprite’s top edge.

number

**subject\_id**

_Subject Id_

What the tile shows. Every facing of one subject shares it, so a tileset can group them.

string format: uuid

nullable

**TileMetadataView**

null

**nine\_slice**

Any of:

**null**

_NineSliceMetadataView_

The insets a 9-slice draws a UI element by, in the image’s own pixels in from each edge.

The corners are drawn at their own size, the edges repeat along their length, and the centre repeats both ways.

object

**left**

required

_Left_

Pixels in from the left edge.

integer

**top**

required

_Top_

Pixels in from the top edge.

integer

**right**

required

_Right_

Pixels in from the right edge.

integer

**bottom**

required

_Bottom_

Pixels in from the bottom edge.

integer

**source**

required

_NineSliceSource_

DETECTED when measured off the pixels, USER when a person set the insets.

string

Allowed values: DETECTED USER

**NineSliceMetadataView**

null

**sprite\_sheet**

Any of:

**null**

_SpriteSheetMetadataView_

The frame grid a sprite sheet was packed on, in the sheet’s own pixels from its top-left corner.

Cells start `margin` pixels in from the sheet’s edges with `spacing` pixels between them.

object

**columns**

required

_Columns_

Cells across.

integer

**rows**

required

_Rows_

Cells down.

integer

**cell\_width**

required

_Cell Width_

Width of one cell in pixels.

integer

**cell\_height**

required

_Cell Height_

Height of one cell in pixels.

integer

**margin**

required

_Margin_

Pixels between the sheet’s edges and the outer cells.

integer

**spacing**

required

_Spacing_

Pixels between neighbouring cells.

integer

**frames**

required

_Frames_

The frames, in play order: left to right, then top to bottom, unless the list orders them otherwise.

Array<object>

_SpriteSheetFrameView_

One frame’s rect on the sheet, in the sheet’s own pixels from its top-left corner.

object

**index**

required

_Index_

The frame’s cell in reading order over the whole grid (left to right, then top to bottom). Cells that hold no frame are left out, so indexes can skip.

integer

**x**

required

_X_

The frame’s left edge on the sheet, in pixels.

integer

**y**

required

_Y_

The frame’s top edge on the sheet, in pixels.

integer

**w**

required

_W_

The frame’s width in pixels.

integer

**h**

required

_H_

The frame’s height in pixels.

integer

**anchor**

Any of:

**SpriteSheetMetadataView**

_TilePointView_object

**x**

required

_X_

Pixels right of the sprite’s left edge.

number

**y**

required

_Y_

Pixels down from the sprite’s top edge.

number

**null**

null

**animations**

required

_Animations_

Named animations over the frames. When empty, play the sheet as one animation named `default` over every frame in `frames` order, at 12 fps, looping.

Array<object>

_SpriteSheetAnimationView_object

**name**

required

_Name_

The animation’s name.

string

**frames**

required

_Frames_

Frame indexes (`frames[].index`), in play order.

Array<integer>

**fps**

required

_Fps_

Frames per second.

number

**loop**

required

_Loop_

Whether the animation restarts after its last frame.

boolean

**TilePointView**

null

**null**

null

**actual\_price\_creative\_units**

_Actual Price Creative Units_

Actual Creative Units charged. Present only on COMPLETE.

number

nullable

**error**

_Error_

Error message. Present only on FAILED.

string

nullable

**error\_code**

_Error Code_

Machine-readable error code. Present only on FAILED. Balance-related values: `INSUFFICIENT_BALANCE` (the workspace ran out of Creative Units — top up and resubmit), `BALANCE_UNAVAILABLE` (the balance could not be verified, retry later) and `USAGE_LIMIT_EXCEEDED` (the member is past their usage limit: ask a workspace admin for more, or wait for it to reset).

string

nullable

##### Example

```json
{
  "status": "in_progress",
  "outputs": [
    {
      "metadata": {
        "tile": {
          "shape": "SQUARE",
          "orientation": "DIAMOND"
        },
        "nine_slice": {
          "source": "DETECTED"
        }
      }
    }
  ]
}
```

### 401

Unauthenticated — missing or invalid Bearer token.

object

**type**

required

string

**title**

required

string

**status**

required

integer

**detail**

required

string

**error\_code**

required

Machine-readable error code: the last path segment of `type`.

string

##### Example

```json
{
  "type": "https://api.layer.ai/errors/ERROR_CODE",
  "title": "Error Title",
  "status": 400,
  "detail": "Human-readable description.",
  "error_code": "ERROR_CODE"
}
```

### 403

Forbidden — insufficient permissions, or the access token lacks the scope the operation requires.

object

**type**

required

string

**title**

required

string

**status**

required

integer

**detail**

required

string

**error\_code**

required

Machine-readable error code: the last path segment of `type`.

string

##### Example

```json
{
  "type": "https://api.layer.ai/errors/ERROR_CODE",
  "title": "Error Title",
  "status": 400,
  "detail": "Human-readable description.",
  "error_code": "ERROR_CODE"
}
```

### 404

Resource not found.

object

**type**

required

string

**title**

required

string

**status**

required

integer

**detail**

required

string

**error\_code**

required

Machine-readable error code: the last path segment of `type`.

string

##### Example

```json
{
  "type": "https://api.layer.ai/errors/ERROR_CODE",
  "title": "Error Title",
  "status": 400,
  "detail": "Human-readable description.",
  "error_code": "ERROR_CODE"
}
```

### 409

The outcome of the request with this `Idempotency-Key` is not known yet: it is still running, or it failed without a stored response. Retry after the number of seconds in `Retry-After`.

object

**type**

required

string

**title**

required

string

**status**

required

integer

**detail**

required

string

**error\_code**

required

Machine-readable error code: the last path segment of `type`.

string

##### Example

```json
{
  "type": "https://api.layer.ai/errors/ERROR_CODE",
  "title": "Error Title",
  "status": 400,
  "detail": "Human-readable description.",
  "error_code": "ERROR_CODE"
}
```

### 422

Invalid input parameters, or an `Idempotency-Key` reused for a different request.

object

**type**

required

string

**title**

required

string

**status**

required

integer

**detail**

required

string

**error\_code**

required

Machine-readable error code: the last path segment of `type`.

string

##### Example

```json
{
  "type": "https://api.layer.ai/errors/ERROR_CODE",
  "title": "Error Title",
  "status": 400,
  "detail": "Human-readable description.",
  "error_code": "ERROR_CODE"
}
```

### 429

Rate limited — retry after the number of seconds in `Retry-After`.

object

**type**

required

string

**title**

required

string

**status**

required

integer

**detail**

required

string

**error\_code**

required

Machine-readable error code: the last path segment of `type`.

string

##### Example

```json
{
  "type": "https://api.layer.ai/errors/ERROR_CODE",
  "title": "Error Title",
  "status": 400,
  "detail": "Human-readable description.",
  "error_code": "ERROR_CODE"
}
```

### 500

Internal server error.

object

**type**

required

string

**title**

required

string

**status**

required

integer

**detail**

required

string

**error\_code**

required

Machine-readable error code: the last path segment of `type`.

string

##### Example

```json
{
  "type": "https://api.layer.ai/errors/ERROR_CODE",
  "title": "Error Title",
  "status": 400,
  "detail": "Human-readable description.",
  "error_code": "ERROR_CODE"
}
```
