Get Async Chat Completion
curl --request GET \
--url https://api.perplexity.ai/v1/async/sonar/{api_request} \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.perplexity.ai/v1/async/sonar/{api_request}"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.perplexity.ai/v1/async/sonar/{api_request}', 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/v1/async/sonar/{api_request}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.perplexity.ai/v1/async/sonar/{api_request}"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.perplexity.ai/v1/async/sonar/{api_request}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.perplexity.ai/v1/async/sonar/{api_request}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"id": "<string>",
"model": "<string>",
"created_at": 123,
"started_at": 123,
"completed_at": 123,
"response": {
"id": "<string>",
"model": "<string>",
"created": 123,
"choices": [
{
"index": 123,
"message": {
"content": "<string>"
},
"delta": {
"content": "<string>"
}
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123,
"cost": {
"input_tokens_cost": 123,
"output_tokens_cost": 123,
"total_cost": 123,
"reasoning_tokens_cost": 123,
"request_cost": 123,
"citation_tokens_cost": 123,
"search_queries_cost": 123
},
"search_context_size": "<string>",
"citation_tokens": 123,
"num_search_queries": 123,
"reasoning_tokens": 123
},
"object": "chat.completion",
"citations": [
"<string>"
],
"search_results": [
{
"title": "<string>",
"url": "<string>",
"date": "<string>",
"last_updated": "<string>",
"snippet": "",
"source": "web"
}
],
"images": [
{
"image_url": "<string>",
"origin_url": "<string>",
"title": "<string>",
"width": 123,
"height": 123
}
],
"related_questions": [
"<string>"
]
},
"failed_at": 123,
"error_message": "<string>"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Sonar API
Get Async Chat Completion
Retrieve the response for a given asynchronous chat completion request.
GET
/
v1
/
async
/
sonar
/
{api_request}
Get Async Chat Completion
curl --request GET \
--url https://api.perplexity.ai/v1/async/sonar/{api_request} \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.perplexity.ai/v1/async/sonar/{api_request}"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.perplexity.ai/v1/async/sonar/{api_request}', 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/v1/async/sonar/{api_request}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.perplexity.ai/v1/async/sonar/{api_request}"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.perplexity.ai/v1/async/sonar/{api_request}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.perplexity.ai/v1/async/sonar/{api_request}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"id": "<string>",
"model": "<string>",
"created_at": 123,
"started_at": 123,
"completed_at": 123,
"response": {
"id": "<string>",
"model": "<string>",
"created": 123,
"choices": [
{
"index": 123,
"message": {
"content": "<string>"
},
"delta": {
"content": "<string>"
}
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123,
"cost": {
"input_tokens_cost": 123,
"output_tokens_cost": 123,
"total_cost": 123,
"reasoning_tokens_cost": 123,
"request_cost": 123,
"citation_tokens_cost": 123,
"search_queries_cost": 123
},
"search_context_size": "<string>",
"citation_tokens": 123,
"num_search_queries": 123,
"reasoning_tokens": 123
},
"object": "chat.completion",
"citations": [
"<string>"
],
"search_results": [
{
"title": "<string>",
"url": "<string>",
"date": "<string>",
"last_updated": "<string>",
"snippet": "",
"source": "web"
}
],
"images": [
{
"image_url": "<string>",
"origin_url": "<string>",
"title": "<string>",
"width": 123,
"height": 123
}
],
"related_questions": [
"<string>"
]
},
"failed_at": 123,
"error_message": "<string>"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}For new integrations, use the Agent API - see the migration guide.
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Path Parameters
Response
Successful Response
Unique identifier for the async request
Model used for the request
Unix timestamp when the request was created
Current processing status of the request
Available options:
CREATED, IN_PROGRESS, COMPLETED, FAILED Unix timestamp when processing started
Unix timestamp when processing completed
Show child attributes
Show child attributes
Unix timestamp when the request failed (if applicable)
Error message if the request failed
Was this page helpful?
⌘I