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

# Rebuild, cancel, delete

> Manage a template over time: trigger new builds, cancel in-flight ones, delete stale templates

## Rebuild

Queue a new build for an existing template, e.g. after a failed build, or to pick up an updated base image.

<CodeGroup>
  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"vitesse-dark"}}
  const build = await template.rebuild()
  console.log(`Build queued: ${build.id}`)
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"vitesse-dark"}}
  build = template.rebuild()
  print(f"Build queued: {build.id}")
  ```
</CodeGroup>

Rebuild is **idempotent**: if an in-flight build already exists with the same configuration, you get back the existing build instead of a duplicate.

## List and inspect builds

<CodeGroup>
  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"vitesse-dark"}}
  const builds = await template.listBuilds({ limit: 10 })
  for (const b of builds) {
    console.log(b.id, b.status, b.errorMessage ?? "")
  }

  const build = await template.getBuild(builds[0].id)
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"vitesse-dark"}}
  builds = template.list_builds(limit=10)
  for b in builds:
      print(b.id, b.status, b.error_message or "")

  build = template.get_build(builds[0].id)
  ```
</CodeGroup>

## Cancel an in-flight build

<CodeGroup>
  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"vitesse-dark"}}
  await template.cancelBuild(build.id)
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"vitesse-dark"}}
  template.cancel_build(build.id)
  ```
</CodeGroup>

`cancelBuild` is a no-op for builds already in a terminal state.

## Delete a template

<CodeGroup>
  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"vitesse-dark"}}
  await template.delete()

  // Or by UUID
  await Template.deleteById("7a3f2b8c-1234-...")
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"vitesse-dark"}}
  template.delete()

  # Or by UUID
  Template.delete_by_id("7a3f2b8c-1234-...")
  ```
</CodeGroup>

Both calls are idempotent on `404`. If any non-destroyed sandbox still references the template, the call raises `ConflictError`; destroy those sandboxes first. Once the delete succeeds the template's `name` is released for reuse — you can immediately create a new template with the same name.

## Related

* [Create a template](/templates/create)
* [BuildSpec reference](/templates/build-spec)
* [SDK reference: Template](/sdk-reference/template)
