Create a conversation
Creates a new AI conversation, the container for messages exchanged with an assistant, and returns the created conversation.
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const conversation = await client.ai.conversations.create();
console.log(conversation.id);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
conversation = client.ai.conversations.create()
print(conversation.id)
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"),
)
conversation, err := client.AI.Conversations.New(context.TODO(), telnyx.AIConversationNewParams{})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", conversation.ID)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.ai.conversations.Conversation;
import com.telnyx.sdk.models.ai.conversations.ConversationCreateParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
Conversation conversation = client.ai().conversations().create();
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
conversation = telnyx.ai.conversations.create
puts(conversation)<?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 {
$conversation = $client->ai->conversations->create(
metadata: ['foo' => 'string'], name: 'name'
);
var_dump($conversation);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx ai:conversations create \
--api-key 'My API Key'curl --request POST \
--url https://api.telnyx.com/v2/ai/conversations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "string"
}
'{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"created_at": "2025-04-15T13:07:28.764Z",
"metadata": {
"telnyx_conversation_channel": "sms",
"telnyx_agent_target": "+13128675309",
"telnyx_end_user_target": "+13128675309",
"assistant_id": "assistant-123"
},
"last_message_at": "2025-04-15T13:07:28.764Z",
"name": ""
}{
"errors": [
{
"code": "10007",
"title": "<string>",
"detail": "<string>",
"source": {
"pointer": "<string>"
}
}
]
}{
"errors": [
{
"code": "10036",
"title": "Resource is being processed",
"detail": "A request with this Idempotency-Key is already being processed.",
"source": {
"pointer": "/header/Idempotency-Key"
}
}
]
}{
"errors": [
{
"code": "10007",
"title": "<string>",
"detail": "<string>",
"source": {
"pointer": "<string>"
}
}
]
}{
"detail": [
{
"loc": [
"body",
"name"
],
"msg": "Field required",
"type": "missing"
}
]
}{
"errors": [
{
"code": "10007",
"title": "<string>",
"detail": "<string>",
"source": {
"pointer": "<string>"
}
}
]
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Headers
Optional opaque, unquoted key for safely retrying the same logical request. Keys must contain 1 to 255 letters, numbers, hyphens, or underscores. Generate a unique UUID v4 for each operation and reuse it only when retrying that operation with the same request. Invalid headers—including duplicate, empty, malformed, or overlong values—return 400 with error code 10015. A request already in progress with the same key returns 409; reusing the key with a different request returns 422. Only successful responses are replayed, for up to 24 hours. Do not include sensitive data in the key.
1 - 255^[A-Za-z0-9_-]{1,255}$Body
Response
Successful Response
"3fa85f64-5717-4562-b3fc-2c963f66afa6"
The datetime the conversation was created.
"2025-04-15T13:07:28.764Z"
Metadata associated with the conversation. Telnyx provides several pieces of metadata, but customers can also add their own. The reserved field ai_disabled (boolean) can be set to true to prevent AI-generated responses on this conversation. When ai_disabled is true, calls to the chat endpoint will return a 400 error. Set to false or remove the field to re-enable AI responses. This is useful when a human agent needs to take over the conversation mid-stream (e.g., a technician stepping in while AI was messaging a resident).
Show child attributes
Show child attributes
{
"telnyx_conversation_channel": "sms",
"telnyx_agent_target": "+13128675309",
"telnyx_end_user_target": "+13128675309",
"assistant_id": "assistant-123"
}
The datetime of the latest message in the conversation.
"2025-04-15T13:07:28.764Z"
""
Was this page helpful?
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const conversation = await client.ai.conversations.create();
console.log(conversation.id);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
conversation = client.ai.conversations.create()
print(conversation.id)
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"),
)
conversation, err := client.AI.Conversations.New(context.TODO(), telnyx.AIConversationNewParams{})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", conversation.ID)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.ai.conversations.Conversation;
import com.telnyx.sdk.models.ai.conversations.ConversationCreateParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
Conversation conversation = client.ai().conversations().create();
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
conversation = telnyx.ai.conversations.create
puts(conversation)<?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 {
$conversation = $client->ai->conversations->create(
metadata: ['foo' => 'string'], name: 'name'
);
var_dump($conversation);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx ai:conversations create \
--api-key 'My API Key'curl --request POST \
--url https://api.telnyx.com/v2/ai/conversations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "string"
}
'{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"created_at": "2025-04-15T13:07:28.764Z",
"metadata": {
"telnyx_conversation_channel": "sms",
"telnyx_agent_target": "+13128675309",
"telnyx_end_user_target": "+13128675309",
"assistant_id": "assistant-123"
},
"last_message_at": "2025-04-15T13:07:28.764Z",
"name": ""
}{
"errors": [
{
"code": "10007",
"title": "<string>",
"detail": "<string>",
"source": {
"pointer": "<string>"
}
}
]
}{
"errors": [
{
"code": "10036",
"title": "Resource is being processed",
"detail": "A request with this Idempotency-Key is already being processed.",
"source": {
"pointer": "/header/Idempotency-Key"
}
}
]
}{
"errors": [
{
"code": "10007",
"title": "<string>",
"detail": "<string>",
"source": {
"pointer": "<string>"
}
}
]
}{
"detail": [
{
"loc": [
"body",
"name"
],
"msg": "Field required",
"type": "missing"
}
]
}{
"errors": [
{
"code": "10007",
"title": "<string>",
"detail": "<string>",
"source": {
"pointer": "<string>"
}
}
]
}