japhetgan
11/03/2025, 8:39 AMAI Evy
11/03/2025, 8:39 AMAI Evy
11/03/2025, 8:39 AMchat_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:
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) ;AI Evy
11/03/2025, 8:39 AMAI Evy
11/03/2025, 8:39 AMAI Evy
11/03/2025, 8:40 AMjaphetgan
11/03/2025, 8:45 AMAI Evy
11/03/2025, 8:45 AMAI Evy
11/03/2025, 8:45 AMagent_id to start a new conversation :
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) ]() :AI Evy
11/03/2025, 8:45 AMjavascript
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) ]() .AI Evy
11/03/2025, 8:46 AMAI Evy
11/03/2025, 8:46 AMjaphetgan
11/03/2025, 8:47 AMAI Evy
11/03/2025, 8:47 AMAI Evy
11/03/2025, 8:47 AMchat_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?
**AI Evy
11/03/2025, 8:47 AMAI Evy
11/03/2025, 8:47 AM