# Subscription API

Export a subscription proxy list and update the settings that control generated proxy usernames.

The Subscription API lets you programmatically export the proxy list for one subscription and update the synced settings used to generate that list.

Use it when you want to rotate between countries, create new sticky sessions, switch between HTTP and SOCKS5 output, or retrieve the latest proxy lines without opening the dashboard.

**Quick answer:** update the subscription's saved settings with a `PATCH` request, then call the export endpoint to retrieve a fresh proxy list that reflects those settings.

## Authentication

All Subscription API examples use your API key in the `X-API-Key` header.

```txt
X-API-Key: {apiKey}
```

You can find the key in the dashboard. The key must belong to the owner of the subscription you are trying to access.

The `apiKey` query parameter still works for existing integrations, but it is **deprecated**. Do not put your key in a URL. If you send both, the header wins.

If the API key is missing, invalid, or belongs to a different account than the subscription owner, the API returns `403` with this body:

```json
{
  "success": false,
  "error": "unauthorized"
}
```

A subscription ID that does not exist returns an error response. Settings and city-combinations return `400` with the JSON error `No subscription found`.

## Find locations for a subscription

Use the location routes to get active geotargeting options for a subscription. Each request uses the subscription's product type. Each route requires the subscription owner's API key.

Get countries:

```http
GET https://api.thunderproxy.com/v1/api/subscriptions/{subscriptionId}/locations/countries
X-API-Key: {apiKey}
```

Get states for a country:

```http
GET https://api.thunderproxy.com/v1/api/subscriptions/{subscriptionId}/locations/states?country=US
X-API-Key: {apiKey}
```

Get cities for a state:

```http
GET https://api.thunderproxy.com/v1/api/subscriptions/{subscriptionId}/locations/cities?country=US&state=NY
X-API-Key: {apiKey}
```

Each response uses the standard JSON envelope. The `connectionString` field is the exact location component to append to the proxy username. Use `displayName` only as a label.

```json
{
  "success": true,
  "data": [
    {
      "connectionString": "res-US_NY",
      "displayName": "New York",
      "country": "US",
      "state": "NY"
    }
  ]
}
```

The API returns only active locations for that subscription's product. A valid location with no child locations returns an empty `data` array. The API returns `400` when a required parent location is missing or unavailable. It returns `404` when the subscription does not exist. Static subscriptions do not support geotargeting.

The former `/geo`, `/states`, and `/cities` placeholder routes are removed.

## Export a proxy list

```http
GET https://api.thunderproxy.com/v1/public/subscriptions/export/{subscriptionId}/txt
X-API-Key: {apiKey}
```

The response is plain text (`Content-Type: text/plain; charset=utf-8`). Each line is one proxy entry, separated by `\n`.

```txt
gateway.thunderproxy.com:12345:username-res-US-sid-12345678:password
gateway.thunderproxy.com:12345:username-res-DE-sid-87654321:password
```

The export endpoint does not accept location, rotation, or protocol query parameters. It reads the saved settings for that subscription and returns the current generated list.

## Update synced settings

```http
PATCH https://api.thunderproxy.com/v1/api/subscriptions/{subscriptionId}/settings
X-API-Key: {apiKey}
Content-Type: application/json
```

Send the settings as a JSON body. This endpoint updates the saved settings used by the export endpoint. Only residential and datacenter rotating subscriptions are supported; static subscriptions return an error.

On success it returns a JSON envelope:

```json
{
  "success": true,
  "data": {
    "updated": true
  }
}
```

On an error, the body is a JSON envelope with `success: false` and an `error` message, such as `Invalid country provided` or `Invalid state provided`. Invalid input does not change the saved settings.

After updating settings, call the export endpoint again to retrieve the updated list.

> **Deprecated:** `GET /v1/api/subscriptions/{subscriptionId}/settings?...` with query parameters still works for existing integrations. It returns the same JSON envelope and a `Deprecation: true` header. Move to `PATCH`.

## Settings fields

| Field      | Values                                 | Notes                                                                                    |
| ---------- | -------------------------------------- | ---------------------------------------------------------------------------------------- |
| `country`  | `ANY`, `US`, `DE`, `FR`, ...           | Country code. Use `ANY` to remove country targeting.                                     |
| `state`    | State code/name from the location list | Use with `country`.                                                                      |
| `city`     | City name from the location list       | Use with `country` and, when applicable, `state`.                                        |
| `rotation` | `rotating`, `sticky`                   | `rotating` returns one rotating username. `sticky` generates multiple session usernames. |
| `sessions` | Integer, `1` to `20000`                | Number of sticky session usernames to generate.                                          |
| `protocol` | `http`, `socks5`                       | Applies when SOCKS5 gateway support is enabled for the subscription product.             |

## Example: change country and export

**cURL**

```bash
curl -X PATCH "https://api.thunderproxy.com/v1/api/subscriptions/sub_123/settings" \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"country": "DE", "rotation": "rotating"}'

curl -H "X-API-Key: YOUR_API_KEY" "https://api.thunderproxy.com/v1/public/subscriptions/export/sub_123/txt"
```

**Python**

```python
import requests

API_KEY = "YOUR_API_KEY"
SUBSCRIPTION_ID = "sub_123"
HEADERS = {"X-API-Key": API_KEY}

requests.patch(
f"https://api.thunderproxy.com/v1/api/subscriptions/{SUBSCRIPTION_ID}/settings",
headers=HEADERS,
json={"country": "DE", "rotation": "rotating"},
).raise_for_status()

export_response = requests.get(
f"https://api.thunderproxy.com/v1/public/subscriptions/export/{SUBSCRIPTION_ID}/txt",
headers=HEADERS,
)
export_response.raise_for_status()
print(export_response.text)
```

**JavaScript**

```javascript
const API_KEY = "YOUR_API_KEY";
const SUBSCRIPTION_ID = "sub_123";
const headers = { "X-API-Key": API_KEY };

const settingsResponse = await fetch(
`https://api.thunderproxy.com/v1/api/subscriptions/${SUBSCRIPTION_ID}/settings`,
{
method: "PATCH",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({ country: "DE", rotation: "rotating" }),
},
);

if (!settingsResponse.ok) {
throw new Error(`Settings request failed with status ${settingsResponse.status}`);
}

const exportResponse = await fetch(
`https://api.thunderproxy.com/v1/public/subscriptions/export/${SUBSCRIPTION_ID}/txt`,
{ headers },
);

if (!exportResponse.ok) {
throw new Error(`Export request failed with status ${exportResponse.status}`);
}

console.log(await exportResponse.text());
```

The exported usernames will target Germany until you change the subscription settings again.

## Example: create sticky sessions

**cURL**

```bash
curl -X PATCH "https://api.thunderproxy.com/v1/api/subscriptions/sub_123/settings" \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"country": "US", "rotation": "sticky", "sessions": 10}'

curl -H "X-API-Key: YOUR_API_KEY" "https://api.thunderproxy.com/v1/public/subscriptions/export/sub_123/txt"
```

**Python**

```python
import requests

API_KEY = "YOUR_API_KEY"
SUBSCRIPTION_ID = "sub_123"
HEADERS = {"X-API-Key": API_KEY}

requests.patch(
f"https://api.thunderproxy.com/v1/api/subscriptions/{SUBSCRIPTION_ID}/settings",
headers=HEADERS,
json={"country": "US", "rotation": "sticky", "sessions": 10},
).raise_for_status()

export_response = requests.get(
f"https://api.thunderproxy.com/v1/public/subscriptions/export/{SUBSCRIPTION_ID}/txt",
headers=HEADERS,
)
export_response.raise_for_status()
print(export_response.text)
```

**JavaScript**

```javascript
const API_KEY = "YOUR_API_KEY";
const SUBSCRIPTION_ID = "sub_123";
const headers = { "X-API-Key": API_KEY };

const settingsResponse = await fetch(
`https://api.thunderproxy.com/v1/api/subscriptions/${SUBSCRIPTION_ID}/settings`,
{
method: "PATCH",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({ country: "US", rotation: "sticky", sessions: 10 }),
},
);

if (!settingsResponse.ok) {
throw new Error(`Settings request failed with status ${settingsResponse.status}`);
}

const exportResponse = await fetch(
`https://api.thunderproxy.com/v1/public/subscriptions/export/${SUBSCRIPTION_ID}/txt`,
{ headers },
);

if (!exportResponse.ok) {
throw new Error(`Export request failed with status ${exportResponse.status}`);
}

console.log(await exportResponse.text());
```

Sticky exports include session IDs in the username, such as `-sid-12345678`. Each generated username can be used independently, so you can run multiple sessions at the same time as long as the subscription is active.

## Example: export SOCKS5 URIs

**cURL**

```bash
curl -X PATCH "https://api.thunderproxy.com/v1/api/subscriptions/sub_123/settings" \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"protocol": "socks5"}'

curl -H "X-API-Key: YOUR_API_KEY" "https://api.thunderproxy.com/v1/public/subscriptions/export/sub_123/txt"
```

**Python**

```python
import requests

API_KEY = "YOUR_API_KEY"
SUBSCRIPTION_ID = "sub_123"
HEADERS = {"X-API-Key": API_KEY}

requests.patch(
f"https://api.thunderproxy.com/v1/api/subscriptions/{SUBSCRIPTION_ID}/settings",
headers=HEADERS,
json={"protocol": "socks5"},
).raise_for_status()

export_response = requests.get(
f"https://api.thunderproxy.com/v1/public/subscriptions/export/{SUBSCRIPTION_ID}/txt",
headers=HEADERS,
)
export_response.raise_for_status()
print(export_response.text)
```

**JavaScript**

```javascript
const API_KEY = "YOUR_API_KEY";
const SUBSCRIPTION_ID = "sub_123";
const headers = { "X-API-Key": API_KEY };

const settingsResponse = await fetch(
`https://api.thunderproxy.com/v1/api/subscriptions/${SUBSCRIPTION_ID}/settings`,
{
method: "PATCH",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({ protocol: "socks5" }),
},
);

if (!settingsResponse.ok) {
throw new Error(`Settings request failed with status ${settingsResponse.status}`);
}

const exportResponse = await fetch(
`https://api.thunderproxy.com/v1/public/subscriptions/export/${SUBSCRIPTION_ID}/txt`,
{ headers },
);

if (!exportResponse.ok) {
throw new Error(`Export request failed with status ${exportResponse.status}`);
}

console.log(await exportResponse.text());
```

If the subscription supports SOCKS5 gateway export and the proxy format is URI output, exported lines use the `socks5h://` scheme.

## Export formats

The dashboard controls the proxy output format. The export endpoint returns whichever format is saved on the subscription.

| Saved format                     | Output example                                                                                               |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| `host:port:user:pass`            | `gw.thunderproxy.net:5959:username:password`                                                                 |
| `user:pass@host:port`            | `username:password@gw.thunderproxy.net:5959`                                                                 |
| `protocol://user:pass@host:port` | `http://username:password@gw.thunderproxy.net:5959` or `socks5h://username:password@gw.thunderproxy.net:9595` |

## Product behavior

Residential and datacenter rotating subscriptions support location, rotation, sessions, and protocol updates.

Static ISP subscriptions use stable proxy entries. Static ISP export settings are controlled from the dashboard and do not use the `/v1/api/subscriptions/{subscriptionId}/settings` endpoint.

Exported proxy lists continue to work while the subscription is active. If a subscription expires, is deleted, or runs out of available usage, exported entries may stop authenticating.

## Next steps

Generate city-combination usernames for rotating subscriptions:

```http
GET https://api.thunderproxy.com/v1/api/subscriptions/{subscriptionId}/city-combinations?amount=2
X-API-Key: {apiKey}
```

`amount` defaults to `2` and can be at most `5`. The response is a plain-text attachment named `city_combinations.txt`.

If the generator fails on the server, the endpoint returns a JSON `500` error with `success: false`. It never returns an empty `200`. Retry, and contact support if it keeps happening.

- [Download the Subscription API OpenAPI specification](/openapi/subscription-api.yaml).
- [View account and subscription status with the Account API](/api/account-api).
- [Choose proxy string formats](/setup/proxy-formats).
- [Understand Activity and Renewals](/subscriptions/activity-and-renewals).
