https://retellai.com/?utm_source=discord&utm_medium=seo logo
I need a way to programmatically (via an API) pass...
# ❓・ai-evy-support
n
@AI Evy I need a way to programmatically (via an API) pass an incoming chat message into a chat agent (text) and have the agent programmatically respond.
a
Thanks for tagging me @n8gr80753. I'll look through relevant sources and get back to you shortly.
### Answer You can programmatically pass incoming chat messages to a text agent and receive responses using Retell AI's Chat API [(1) ]() . Here's the workflow: 1. Create a chat session using the Create Chat endpoint [(2) ]() :
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) ;
2. Send messages and get agent responses using the Create Chat Completion endpoint [(1) ]() :
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) ;
The Create Chat Completion endpoint accepts a
chat_id
and the user's message
content
, then returns new messages generated by the agent . The response includes any tool call invocations and their results, but does not include the original input messages . **
​ To learn more, see the sources I considered: [[1] Create Chat Completion](https://docs.retellai.com/api-references/create-chat-completion) [[2] Create Chat](https://docs.retellai.com/api-references/create-chat) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
n
@AI Evy where do I get my API Key?
a
Thanks for the follow-up, @n8gr80753. I'll get back to you soon.
### Answer You can find your API keys in the Retell AI Dashboard under the "API Keys" section in the left side menu [(1) ]() . API keys are used to authenticate your requests to REST API endpoints, SDK integrations, and webhook endpoints [(2) ]() . Each workspace can have multiple API keys, all sharing the same permission level . To authenticate your REST API requests, include your API key in the request headers :
Copy code
Authorization: Bearer YOUR_API_KEY
Keep your API keys secure and never share them in public repositories or client-side code .
​ To learn more, see the sources I considered: [[1] where can I find my api keys?](https://discord.com/channels/1186424376300679209/1322586375941259425) [[2] API Key Overview](https://docs.retellai.com/accounts/api-keys-overview) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.