# Download a submission

```http
GET /api/public/v1/competitions/mathematics-distillation-challenge-equational-theories-stage2/submissions/{submissionId}/download
```

**Scope**: `competition.read`.

Downloads the exact UTF-8 `solverCode` stored in one current Stage 2 entry. The entry must belong to the caller's active competition team; any active team member may download it.

This endpoint returns a file response rather than the standard JSON success envelope.

## Path parameter

| Parameter | Type | Description |
| :-------- | :--- | :---------- |
| `submissionId` | string | Opaque ID obtained from [List my submissions](./list-my-submissions.md) or [Get a submission by ID](./get-submission.md). |

## Example request

```bash
curl "https://api.sair.foundation/api/public/v1/competitions/mathematics-distillation-challenge-equational-theories-stage2/submissions/sub_01JSTAGE200000000000000001/download" \
  -H "Authorization: Bearer $SAIR_API_KEY" \
  -OJ
```

`-O` saves the response as a file, and `-J` uses the filename supplied by the API.

## Response

```http
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Content-Disposition: attachment; filename="stage2-sub_01JSTAGE200000000000000001-solver.py"
```

The body is the exact stored source, without a JSON wrapper or server-side reformatting:

```python
import json

context = json.loads(input())
print(
    json.dumps({"call": "judge", "verdict": "true", "code": "by rfl"}),
    flush=True,
)
judge_result = json.loads(input())
```

The short solver illustrates the response format, not a general competition strategy.

## Resource behavior

- The filename is `stage2-{submissionId}-solver.py`.
- Replacing the same `(track, modelId)` pair updates its stable entry. Downloading the same `submissionId` afterward returns the latest accepted source, not a historical revision.
- The server preserves the stored source bytes after UTF-8 encoding; it does not append a newline or normalize line endings.
- The ID is resolved inside the competition named in the URL and against the caller's current active team.

## Errors

| HTTP | Code | When |
| :---: | :--- | :--- |
| `404` | `NOT_FOUND` | The competition is not publicly visible, the submission does not exist in that competition, or it is not accessible to the caller's current active team. |

Error responses use the standard JSON error envelope even though a successful response is plain text. These not-found cases intentionally share one response so the endpoint does not reveal whether another team's submission exists. Shared authentication, scope, and rate-limit errors are documented in [Errors](../../../errors.md).
