---
title: "Regenerate a device code"
method: POST
path: "/agents/{agentId}/device-codes"
tags: ["Agent Management"]
---

# Regenerate a device code

`POST /agents/{agentId}/device-codes`

Generate a new device code for an existing agent. Use this when the original device code has expired before being redeemed, or when the agent software needs to be reinstalled. Any previously issued unredeemed device codes for this agent are invalidated.

## Response `201`

New device code generated successfully

- AgentDeviceCode
  - `code` string, required — Human-readable device code used to install and connect the agent software.
  - `agentId` string, required — The agent this device code belongs to.
  - `expiresAt` string, date-time, required — Timestamp when this device code expires.
  - `redeemed` boolean, required — Whether this device code has already been redeemed by the agent.

## Other responses

- `400` — Bad request
- `401` — Unauthorized
- `404` — Agent not found
- `409` — Conflict - Agent already has an active connection and cannot regenerate a device code
- `500` — Internal service error

---

[API](https://skmtc.net/lightsparkdev/apis/grid-api.md) · [All operations](https://skmtc.net/lightsparkdev/apis/grid-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/lightsparkdev/grid-api/versions/d0bce562bffd/schema)
