# Download agent code

`GET /agents/{agent_name}/code:download`

Downloads the code zip for a code-based hosted agent.
Returns the previously-uploaded zip (`application/zip`).

If `agent_version` is supplied, returns that version's code zip; otherwise
returns the latest version's code zip.

The SHA-256 digest of the returned bytes matches the `content_hash` on the
resolved version's `code_configuration`.

## Parameters

### Path parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `agent_name` | `string` | Yes | The name of the agent. |

### Query parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `agent_version` | `string` | No | The version of the agent whose code zip should be downloaded. If omitted, the latest version's code zip is returned. |
| `api-version` | `string` | Yes | The API version to use for this operation. |

### Header parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Foundry-Features` | `enum` | No | A feature flag opt-in required when using preview operations or modifying persisted preview resources. _Constant:_ `CodeAgents=V1Preview` |

## Responses

### 200 — Response body for downloading a hosted agent's code zip.
Body is the raw zip bytes; `Content-Type` declares `application/zip` so clients
can route to a zip-aware handler. Streaming is preserved (`bytes` body) regardless
of the content-type label.

Content-Type: `application/zip`

| Type | Description |
|------|-------------|
| `any` | — |

### 4XX — Client error

Content-Type: `application/json`

Error response for API failures.

| Property | Type | Required | Description |
|----------|------|----------|-------------|
| `error` | `OpenAI.Error` | Yes |  |

#### `error` — `OpenAI.Error`

| Property | Type | Required | Description |
|----------|------|----------|-------------|
| `code` | `string \| null` | Yes |  |
| `message` | `string` | Yes |  |
| `param` | `string \| null` | No |  |
| `type` | `string` | No |  |
| `details` | `OpenAI.Error[]` | No |  |
| `additionalInfo` | `object` | No |  |
| `debugInfo` | `object` | No |  |

### 5XX — Server error

Content-Type: `application/json`

Error response for API failures.

| Property | Type | Required | Description |
|----------|------|----------|-------------|
| `error` | `OpenAI.Error` | Yes |  |

#### `error` — `OpenAI.Error`

| Property | Type | Required | Description |
|----------|------|----------|-------------|
| `code` | `string \| null` | Yes |  |
| `message` | `string` | Yes |  |
| `param` | `string \| null` | No |  |
| `type` | `string` | No |  |
| `details` | `OpenAI.Error[]` | No |  |
| `additionalInfo` | `object` | No |  |
| `debugInfo` | `object` | No |  |
