> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://akamai.ferndocs.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://akamai.ferndocs.com/_mcp/server.

# Create a secure token

POST https://{hostname}/edgeworkers/v1/secure-token
Content-Type: application/json

Generate a JWT authentication token to [enable enhanced debug headers](https://techdocs.akamai.com/edgeworkers/docs/enable-enhanced-debug-headers) for EdgeWorkers.

Reference: https://akamai.ferndocs.com/edge-workers/api/edge-workers-api/secure-tokens/post-secure-token

## Request

### Query parameters

- `accountSwitchKey` (string, optional) — For customers who manage more than one account, this [runs the operation from another account](https://techdocs.akamai.com/developer/docs/manage-many-accounts-with-one-api-client). The Identity and Access Management API provides a [list of available account switch keys](https://techdocs.akamai.com/iam-api/reference/get-client-account-switch-keys).

### Body (application/json)

This endpoint expects an object.

- `expiry` (integer, optional, default: 480) — Number of minutes before the authentication token expires, from 1 to 720 minutes, or 12 hours. The default is `480` for 8 hours.
- `hostname` (string, optional) — __Deprecated__ Use the `hostnames` parameter instead. Hostname for a property. To create an authentication token, provide either the `hostname`, or the `propertyId`, but not both.
- `hostnames` (list of string, optional) — List of hostnames for a property. To create an authentication token, provide either the list of `hostnames`, or the `propertyId`, but not both. Specify `/*` to generate an authentication token valid for all hosts.
- `propertyId` (string, optional) — Unique identifier for a property. To create an authentication token, provide either the `propertyId` or the `hostname`, but not both.

## Response

### 201

A generated JWT authentication token, for use with enhanced debug headers for EdgeWorkers. See [Enhanced debug headers](https://techdocs.akamai.com/edgeworkers/docs/enhanced-debug-header-details).

- `akamaiEwTrace` (string, required) — The JWT authentication token, for use with enhanced debug headers for EdgeWorkers.

## Errors

### 400 Bad Request Error

A specified hostname does not exist in the property.

- `detail` (string, optional) — A description of the error.
- `errorCode` (string, optional) — Internal error code used to assist with troubleshooting by Akamai employees.
- `instance` (string, optional) — Reference to unique instance of the error.
- `status` (integer, optional) — The HTTP code associated with the error.
- `title` (string, optional) — Text representation of the HTTP error code.
- `type` (string, optional) — Reference to additional documentation.

## Examples

**Request**

```json
{
  "expiry": 30,
  "hostname": "www.example.com",
  "hostnames": [
    "www.hostname1.com",
    "www.hostname2.com"
  ],
  "propertyId": "123456789"
}
```

**Response**

```json
{
  "akamaiEwTrace": "eyJ0eXAiOiJKV1Qi ... iu1XOS9eJOl-54Yw"
}
```

**SDK Code**

```python
import requests

url = "https://{hostname}/edgeworkers/v1/secure-token"

querystring = {"accountSwitchKey":"{{accountSwitchKey}}"}

payload = {
    "expiry": 30,
    "hostname": "www.example.com",
    "hostnames": ["www.hostname1.com", "www.hostname2.com"],
    "propertyId": "123456789"
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers, params=querystring)

print(response.json())
```

```javascript
const url = 'https://{hostname}/edgeworkers/v1/secure-token?accountSwitchKey=%7B%7BaccountSwitchKey%7D%7D';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"expiry":30,"hostname":"www.example.com","hostnames":["www.hostname1.com","www.hostname2.com"],"propertyId":"123456789"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://{hostname}/edgeworkers/v1/secure-token?accountSwitchKey=%7B%7BaccountSwitchKey%7D%7D"

	payload := strings.NewReader("{\n  \"expiry\": 30,\n  \"hostname\": \"www.example.com\",\n  \"hostnames\": [\n    \"www.hostname1.com\",\n    \"www.hostname2.com\"\n  ],\n  \"propertyId\": \"123456789\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://{hostname}/edgeworkers/v1/secure-token?accountSwitchKey=%7B%7BaccountSwitchKey%7D%7D")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"expiry\": 30,\n  \"hostname\": \"www.example.com\",\n  \"hostnames\": [\n    \"www.hostname1.com\",\n    \"www.hostname2.com\"\n  ],\n  \"propertyId\": \"123456789\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://{hostname}/edgeworkers/v1/secure-token?accountSwitchKey=%7B%7BaccountSwitchKey%7D%7D")
  .header("Content-Type", "application/json")
  .body("{\n  \"expiry\": 30,\n  \"hostname\": \"www.example.com\",\n  \"hostnames\": [\n    \"www.hostname1.com\",\n    \"www.hostname2.com\"\n  ],\n  \"propertyId\": \"123456789\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://{hostname}/edgeworkers/v1/secure-token?accountSwitchKey=%7B%7BaccountSwitchKey%7D%7D', [
  'body' => '{
  "expiry": 30,
  "hostname": "www.example.com",
  "hostnames": [
    "www.hostname1.com",
    "www.hostname2.com"
  ],
  "propertyId": "123456789"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://{hostname}/edgeworkers/v1/secure-token?accountSwitchKey=%7B%7BaccountSwitchKey%7D%7D");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"expiry\": 30,\n  \"hostname\": \"www.example.com\",\n  \"hostnames\": [\n    \"www.hostname1.com\",\n    \"www.hostname2.com\"\n  ],\n  \"propertyId\": \"123456789\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "expiry": 30,
  "hostname": "www.example.com",
  "hostnames": ["www.hostname1.com", "www.hostname2.com"],
  "propertyId": "123456789"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://{hostname}/edgeworkers/v1/secure-token?accountSwitchKey=%7B%7BaccountSwitchKey%7D%7D")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```