JavaScript
import Retell from 'retell-sdk';
const client = new Retell({
apiKey: process.env['RETELL_API_KEY'], // This is the default and can be omitted
});
const response = await client.chat.createChatCompletion({
chat_id: 'oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD',
content: 'hi how are you doing?',
});
console.log(response.messages);import os
from retell import Retell
client = Retell(
api_key=os.environ.get("RETELL_API_KEY"), # This is the default and can be omitted
)
response = client.chat.create_chat_completion(
chat_id="oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD",
content="hi how are you doing?",
)
print(response.messages)curl --request POST \
--url https://api.retellai.com/create-chat-completion \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"chat_id": "oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD",
"content": "hi how are you doing?"
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.retellai.com/create-chat-completion",
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([
'chat_id' => 'oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD',
'content' => 'hi how are you doing?'
]),
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.retellai.com/create-chat-completion"
payload := strings.NewReader("{\n \"chat_id\": \"oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD\",\n \"content\": \"hi how are you doing?\"\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.retellai.com/create-chat-completion")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"chat_id\": \"oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD\",\n \"content\": \"hi how are you doing?\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.retellai.com/create-chat-completion")
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 \"chat_id\": \"oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD\",\n \"content\": \"hi how are you doing?\"\n}"
response = http.request(request)
puts response.read_body{
"messages": [
{
"message_id": "Jabr9TXYYJHfvl6Syypi88rdAHYHmcq6",
"role": "agent",
"content": "hi how are you doing?",
"created_timestamp": 1703302428855
}
]
}{
"status": "error",
"message": "Invalid request format, please check API reference."
}{
"status": "error",
"message": "API key is missing or invalid."
}{
"status": "error",
"message": "Trial has ended, please add payment method."
}{
"status": "error",
"message": "Cannot find requested asset under given api key."
}{
"status": "error",
"message": "Account rate limited, please throttle your requests."
}{
"status": "error",
"message": "An unexpected server error occurred."
}Chat
Create Chat Completion
Create a chat completion message
POST
/
create-chat-completion
JavaScript
import Retell from 'retell-sdk';
const client = new Retell({
apiKey: process.env['RETELL_API_KEY'], // This is the default and can be omitted
});
const response = await client.chat.createChatCompletion({
chat_id: 'oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD',
content: 'hi how are you doing?',
});
console.log(response.messages);import os
from retell import Retell
client = Retell(
api_key=os.environ.get("RETELL_API_KEY"), # This is the default and can be omitted
)
response = client.chat.create_chat_completion(
chat_id="oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD",
content="hi how are you doing?",
)
print(response.messages)curl --request POST \
--url https://api.retellai.com/create-chat-completion \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"chat_id": "oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD",
"content": "hi how are you doing?"
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.retellai.com/create-chat-completion",
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([
'chat_id' => 'oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD',
'content' => 'hi how are you doing?'
]),
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.retellai.com/create-chat-completion"
payload := strings.NewReader("{\n \"chat_id\": \"oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD\",\n \"content\": \"hi how are you doing?\"\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.retellai.com/create-chat-completion")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"chat_id\": \"oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD\",\n \"content\": \"hi how are you doing?\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.retellai.com/create-chat-completion")
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 \"chat_id\": \"oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD\",\n \"content\": \"hi how are you doing?\"\n}"
response = http.request(request)
puts response.read_body{
"messages": [
{
"message_id": "Jabr9TXYYJHfvl6Syypi88rdAHYHmcq6",
"role": "agent",
"content": "hi how are you doing?",
"created_timestamp": 1703302428855
}
]
}{
"status": "error",
"message": "Invalid request format, please check API reference."
}{
"status": "error",
"message": "API key is missing or invalid."
}{
"status": "error",
"message": "Trial has ended, please add payment method."
}{
"status": "error",
"message": "Cannot find requested asset under given api key."
}{
"status": "error",
"message": "Account rate limited, please throttle your requests."
}{
"status": "error",
"message": "An unexpected server error occurred."
}Authorizations
Authentication header containing API key (find it in dashboard). The format is "Bearer YOUR_API_KEY"
Body
application/json
Response
Successfully created chat completion.
New messages generated by the agent during this completion, including any tool call invocations and their results. Does not include the original input messages.
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- Option 6
- Option 7
Show child attributes
Show child attributes
Was this page helpful?
⌘I

