Assistant Chat
This endpoint allows a client to send a chat message to a specific AI Assistant. The assistant processes the message and returns a relevant reply based on the current conversation context. Refer to the Conversation API to create a conversation, filter existing conversations, fetch messages for a conversation, and manually add messages to a conversation.
POST
/
ai
/
assistants
/
{assistant_id}
/
chat
JavaScript
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const response = await client.ai.assistants.chat('assistant_id', {
content: 'Tell me a joke about cats',
conversation_id: '42b20469-1215-4a9a-8964-c36f66b406f4',
});
console.log(response.content);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
response = client.ai.assistants.chat(
assistant_id="assistant_id",
content="Tell me a joke about cats",
conversation_id="42b20469-1215-4a9a-8964-c36f66b406f4",
)
print(response.content)
package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.AI.Assistants.Chat(
context.TODO(),
"assistant_id",
telnyx.AIAssistantChatParams{
Content: "Tell me a joke about cats",
ConversationID: "42b20469-1215-4a9a-8964-c36f66b406f4",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Content)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.ai.assistants.AssistantChatParams;
import com.telnyx.sdk.models.ai.assistants.AssistantChatResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
AssistantChatParams params = AssistantChatParams.builder()
.assistantId("assistant_id")
.content("Tell me a joke about cats")
.conversationId("42b20469-1215-4a9a-8964-c36f66b406f4")
.build();
AssistantChatResponse response = client.ai().assistants().chat(params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
response = telnyx.ai.assistants.chat(
"assistant_id",
content: "Tell me a joke about cats",
conversation_id: "42b20469-1215-4a9a-8964-c36f66b406f4"
)
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$response = $client->ai->assistants->chat(
'assistant_id',
content: 'Tell me a joke about cats',
conversationID: '42b20469-1215-4a9a-8964-c36f66b406f4',
name: 'Charlie',
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx ai:assistants chat \
--api-key 'My API Key' \
--assistant-id assistant_id \
--content 'Tell me a joke about cats' \
--conversation-id 42b20469-1215-4a9a-8964-c36f66b406f4curl --request POST \
--url https://api.telnyx.com/v2/ai/assistants/{assistant_id}/chat \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"content": "Tell me a joke about cats",
"conversation_id": "42b20469-1215-4a9a-8964-c36f66b406f4",
"name": "Charlie",
"stream": false
}
'{
"content": "Why did the cat sit on the computer? Because it wanted to keep an eye on the mouse!"
}{
"errors": [
{
"code": "10007",
"title": "<string>",
"detail": "<string>",
"source": {
"pointer": "<string>"
}
}
]
}{
"detail": [
{
"loc": [
"body",
"name"
],
"msg": "Field required",
"type": "missing"
}
]
}Authorizations
Body
application/json
When true, the response is streamed as Server-Sent Events (text/event-stream): delta events carry content fragments as they are generated, a final done event carries the full content plus whatsapp_template, and a terminal error event reports failures that happen after streaming started. When false (default), the response is a single JSON object.
Was this page helpful?
JavaScript
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const response = await client.ai.assistants.chat('assistant_id', {
content: 'Tell me a joke about cats',
conversation_id: '42b20469-1215-4a9a-8964-c36f66b406f4',
});
console.log(response.content);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
response = client.ai.assistants.chat(
assistant_id="assistant_id",
content="Tell me a joke about cats",
conversation_id="42b20469-1215-4a9a-8964-c36f66b406f4",
)
print(response.content)
package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.AI.Assistants.Chat(
context.TODO(),
"assistant_id",
telnyx.AIAssistantChatParams{
Content: "Tell me a joke about cats",
ConversationID: "42b20469-1215-4a9a-8964-c36f66b406f4",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Content)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.ai.assistants.AssistantChatParams;
import com.telnyx.sdk.models.ai.assistants.AssistantChatResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
AssistantChatParams params = AssistantChatParams.builder()
.assistantId("assistant_id")
.content("Tell me a joke about cats")
.conversationId("42b20469-1215-4a9a-8964-c36f66b406f4")
.build();
AssistantChatResponse response = client.ai().assistants().chat(params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
response = telnyx.ai.assistants.chat(
"assistant_id",
content: "Tell me a joke about cats",
conversation_id: "42b20469-1215-4a9a-8964-c36f66b406f4"
)
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$response = $client->ai->assistants->chat(
'assistant_id',
content: 'Tell me a joke about cats',
conversationID: '42b20469-1215-4a9a-8964-c36f66b406f4',
name: 'Charlie',
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx ai:assistants chat \
--api-key 'My API Key' \
--assistant-id assistant_id \
--content 'Tell me a joke about cats' \
--conversation-id 42b20469-1215-4a9a-8964-c36f66b406f4curl --request POST \
--url https://api.telnyx.com/v2/ai/assistants/{assistant_id}/chat \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"content": "Tell me a joke about cats",
"conversation_id": "42b20469-1215-4a9a-8964-c36f66b406f4",
"name": "Charlie",
"stream": false
}
'{
"content": "Why did the cat sit on the computer? Because it wanted to keep an eye on the mouse!"
}{
"errors": [
{
"code": "10007",
"title": "<string>",
"detail": "<string>",
"source": {
"pointer": "<string>"
}
}
]
}{
"detail": [
{
"loc": [
"body",
"name"
],
"msg": "Field required",
"type": "missing"
}
]
}