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

# Dynamic API

The Dynamic API is for publishers who want to create many lockers with different destinations. You encrypt each destination with your Dynamic key and append it to one base link. After the visitor finishes with the tasks, they go to that destination instead of the one saved on the link.

The Dynamic API needs a link that already exists, and that link is the base. Create it in the dashboard, or through the [Rest API](https://docs.linkgate.gg/api/rest.md), before you use this.

Open **Settings → API → Dynamic API** and copy the example. Your key is already filled in on that page. This is the same Python example. Replace the three values marked below, then run it. PHP and Node are on that same page if you aren't using Python.

```python theme={null}
import json
import os
from cryptography.hazmat.primitives.ciphers.aead import AESGCM

key = bytes.fromhex("YOUR_DYNAMIC_KEY")
locker = "https://linkgate.gg/access/your-locker"
destination = "https://example.com/page"

nonce = os.urandom(12)
body = json.dumps({"targetUrl": destination}).encode()
sealed = AESGCM(key).encrypt(nonce, body, None)

response = f"{locker}?r={nonce.hex()}{sealed.hex()}"
print(response)
```

`YOUR_DYNAMIC_KEY` is the Dynamic key from **Settings → API → Dynamic API**. On the dashboard, that value is already in the example, so you only replace it here if you copied this page instead. `locker` is the URL of the base link you created. `destination` is the page this visit should open. `response` is the link you share. It is the base URL with `?r=` added.

`r` is hex. It's a 12-byte IV, which is 24 hex characters, followed by the AES-256-GCM ciphertext and its 16-byte auth tag. The JSON inside it is `{"targetUrl": "https://example.com/page"}`.

If `r` is missing, invalid, or it was encrypted with a different key, the visitor is sent to the link's saved destination. A bad `r` doesn't break the link.

If you leak or expose your Dynamic key, contact [support](https://linkgate.gg/dashboard/settings/support) and ask for a reset. You can't rotate it yourself, and a reset turns the old key off immediately.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.