https://retellai.com/?utm_source=discord&utm_medium=seo logo
can you explain Create Chat Completion, when shoul...
# ❓・ai-evy-support
j
@AI Evy can you explain Create Chat Completion, when should I use this API in SMS context
a
Thanks for tagging me @japhetgan. I'll look through relevant sources and get back to you shortly.
### Answer # Create Chat Completion Explained The Create Chat Completion API generates a response from your chat agent when you send it a user message [(1) ]() . It's the core mechanism for having back-and-forth conversations with your Retell AI chat agent [(2) ]() . ## How It Works You provide a
chat_id
(from a previously created chat session) and the user's message content [(1) ]() . The API returns the agent's response in the
messages
array [(2) ]() . Retell automatically stores all conversation history in its database, so you don't need to manage conversation context yourself . Here's the basic code structure:
Copy code
javascript
import Retell from 'retell-sdk';
const client = new Retell({
 apiKey: 'YOUR_RETELL_API_KEY',
}) ;
const response = await client.chat.createChatCompletion({
 chat_id: 'oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD',
 content: 'hi how are you doing?',
}) ;
console.log(response.messages) ;
[(1) ]() ## When to Use in SMS Context For SMS integration with Retell, you would use Create Chat Completion each time you receive an inbound SMS message from a customer [(3) ]() . The workflow would be: 1. First, create a chat session using the Create Chat API [(4) ]() 2. When an SMS arrives, call Create Chat Completion with the message content [(1) ]() 3. Send the agent's response back via SMS [(3) ]() Retell supports SMS functionality when you enable an SMS-capable Twilio number via the SMS addon . You can trigger SMS interactions and build standalone SMS-based chat agents entirely via SMS flow . Note: Chat agents don't support voice-specific functions like call transfers or DTMF [(5) ]() .
​ To learn more, see the sources I considered: [[1] Create Chat Completion](https://docs.retellai.com/api-references/create-chat-completion) [[2] Create Chat Completion](https://docs.retellai.com/deploy/create-chat-completion) [[3] Creating an SMS chatbot from an form submission](https://discord.com/channels/1186424376300679209/1399735172525588521) [[4] Create Chat](https://docs.retellai.com/api-references/create-chat) [[5] Create chat agent](https://docs.retellai.com/build/create-chat-agent) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
j
@AI Evy explain Create Chat and like map out how this API will work togeter?
a
Thanks for the follow-up, @japhetgan. I'll get back to you soon.
### Answer # Create Chat API Explained The Create Chat API initializes a new chat session with your agent [(1) ]() . This is the starting point for any chat-based interaction . ## How It Works You call the Create Chat endpoint with your
agent_id
to start a new conversation :
Copy code
javascript
import Retell from 'retell-sdk';
const client = new Retell({
 apiKey: 'YOUR_RETELL_API_KEY',
}) ;

const chatResponse = await client.chat.create({ agent_id: 'oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD' }) ;
console.log(chatResponse.agent_id) ;
The API returns a
chat_id
that you'll use for all subsequent messages in that conversation . The initial
chat_status
will be
ongoing
. ## How Create Chat and Create Chat Completion Work Together Here's the complete workflow: Step 1: Initialize the conversation - Call Create Chat with your
agent_id
- Receive back a
chat_id
for this session Step 2: Send user messages - Each time the user sends a message, call Create Chat Completion with the
chat_id
and message
content
- The agent processes the message and returns a response Step 3: Continue the conversation - Keep using the same
chat_id
for all messages in that conversation - Retell maintains the conversation history automatically Step 4: Retrieve chat details - Use Get Chat with the
chat_id
to retrieve the full conversation [(2) ]() - Access the complete
transcript
and
message_with_tool_calls
## SMS Context Workflow For SMS specifically, you can also use Create Outbound SMS to initiate conversations [(3) ]() :
Copy code
javascript
import Retell from 'retell-sdk';
const client = new Retell({
 apiKey: 'YOUR_RETELL_API_KEY',
}) ;
const chatResponse = await client.chat.createSMSChat({
 from_number: '+12137771234',
 to_number: '+14155551234',
}) ;
console.log(chatResponse.agent_id) ;
This automatically creates the chat session and sends the initial SMS message based on your agent's configuration . The key point: Create Chat establishes the session once, then you use Create Chat Completion repeatedly with that same
chat_id
for the back-and-forth conversation [(1) ]() .
​ To learn more, see the sources I considered: [[1] Create Chat](https://docs.retellai.com/api-references/create-chat) [[2] Get Chat](https://docs.retellai.com/api-references/get-chat) [[3] Create Outbound SMS](https://docs.retellai.com/api-references/create-sms-chat) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
j
@AI Evy Got it, so how would the back to back conversation would happen? like ibound and outbound SMS hwo would the agent hanlde it in conversatillk flow
a
Thanks for the follow-up, @japhetgan. I'll get back to you soon.
### Answer I don't have specific documentation about how Retell AI handles back-and-forth SMS conversations in Conversational Flow from the available sources. The sources cover creating chat sessions [(1) ]() , generating chat completions [(2) ]() , and creating chat agents [(3) ]() , but don't detail the automatic inbound/outbound SMS handling mechanism within Conversational Flow. Here's what I can tell you based on the available information: What's documented: - You create a chat session once using Create Chat API [(1) ]() - You use Create Chat Completion repeatedly with the same
chat_id
for back-and-forth messages [(2) ]() - Retell automatically stores all conversation history in its database - Chat agents can be configured for SMS when you enable SMS functionality [(3) ]() What's not clear from the sources: - How Retell automatically routes inbound SMS messages to the correct chat session - How the agent maintains context between inbound and outbound SMS in Conversational Flow - Whether webhooks or polling is used for inbound SMS detection For detailed guidance on SMS conversation handling in Conversational Flow, I'd recommend: - Visit [Contact Sales]() - Visit [) Would you like a general answer based on typical SMS chatbot patterns instead? **
​ To learn more, see the sources I considered: [[1] Create Chat](https://docs.retellai.com/api-references/create-chat) [[2] Create Chat Completion](https://docs.retellai.com/api-references/create-chat-completion) [[3] Create chat agent](https://docs.retellai.com/build/create-chat-agent) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.