Generate Auth Token
curl --request POST \
--url https://api.perplexity.ai/generate_auth_token \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"token_name": "Production API Key"
}
'import requests
url = "https://api.perplexity.ai/generate_auth_token"
payload = { "token_name": "Production API Key" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({token_name: 'Production API Key'})
};
fetch('https://api.perplexity.ai/generate_auth_token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.perplexity.ai/generate_auth_token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'token_name' => 'Production API Key'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.perplexity.ai/generate_auth_token"
payload := strings.NewReader("{\n \"token_name\": \"Production API Key\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.perplexity.ai/generate_auth_token")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"token_name\": \"Production API Key\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.perplexity.ai/generate_auth_token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"token_name\": \"Production API Key\"\n}"
response = http.request(request)
puts response.read_body{
"auth_token": "pplx-1234567890abcdef",
"created_at_epoch_seconds": 1735689600,
"token_name": "Production API Key"
}Authentication
Generate Auth Token
Generates a new authentication token for API access.
POST
/
generate_auth_token
Generate Auth Token
curl --request POST \
--url https://api.perplexity.ai/generate_auth_token \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"token_name": "Production API Key"
}
'import requests
url = "https://api.perplexity.ai/generate_auth_token"
payload = { "token_name": "Production API Key" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({token_name: 'Production API Key'})
};
fetch('https://api.perplexity.ai/generate_auth_token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.perplexity.ai/generate_auth_token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'token_name' => 'Production API Key'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.perplexity.ai/generate_auth_token"
payload := strings.NewReader("{\n \"token_name\": \"Production API Key\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.perplexity.ai/generate_auth_token")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"token_name\": \"Production API Key\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.perplexity.ai/generate_auth_token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"token_name\": \"Production API Key\"\n}"
response = http.request(request)
puts response.read_body{
"auth_token": "pplx-1234567890abcdef",
"created_at_epoch_seconds": 1735689600,
"token_name": "Production API Key"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/json
Optional name for the authentication token to help identify its purpose.
Example:
"Production API Key"
Response
200 - application/json
Successfully generated authentication token.
The newly generated authentication token. Store this securely as it cannot be retrieved again.
Example:
"pplx-1234567890abcdef"
Unix timestamp (in seconds) of when the token was created.
Example:
1735689600
The name associated with this token, if provided.
Example:
"Production API Key"
Was this page helpful?
⌘I