retell_create_chat
Start a new chat session with a Retell AI agent by providing an agent ID, enabling personalized conversations through dynamic variables and custom metadata.
Instructions
Create a new chat session with a chat agent.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| agent_id | Yes | The chat agent ID to use for the session | |
| metadata | No | Optional: Custom metadata for the chat session | |
| retell_llm_dynamic_variables | No | Optional: Dynamic variables for personalized responses |
Implementation Reference
- src/index.ts:1139-1140 (handler)The handler logic for the 'retell_create_chat' tool within the executeTool switch statement. It invokes the generic retellRequest helper to perform a POST request to the Retell API endpoint '/create-chat' with the provided arguments.case "retell_create_chat": return retellRequest("/create-chat", "POST", args);
- src/index.ts:203-220 (schema)Input schema defining the parameters for the retell_create_chat tool: requires 'agent_id', optional 'metadata' and 'retell_llm_dynamic_variables'.inputSchema: { type: "object", properties: { agent_id: { type: "string", description: "The chat agent ID to use for the session" }, metadata: { type: "object", description: "Optional: Custom metadata for the chat session" }, retell_llm_dynamic_variables: { type: "object", description: "Optional: Dynamic variables for personalized responses" } }, required: ["agent_id"] }
- src/index.ts:200-221 (registration)Tool registration in the tools array, including name, description, and input schema. This array is returned by the ListTools handler.{ name: "retell_create_chat", description: "Create a new chat session with a chat agent.", inputSchema: { type: "object", properties: { agent_id: { type: "string", description: "The chat agent ID to use for the session" }, metadata: { type: "object", description: "Optional: Custom metadata for the chat session" }, retell_llm_dynamic_variables: { type: "object", description: "Optional: Dynamic variables for personalized responses" } }, required: ["agent_id"] } },
- src/index.ts:23-57 (helper)Generic helper function used by all Retell API tools, including retell_create_chat. Handles authentication, request construction, error handling, and response parsing.async function retellRequest( endpoint: string, method: string = "GET", body?: Record<string, unknown> ): Promise<unknown> { const apiKey = getApiKey(); const headers: Record<string, string> = { "Authorization": `Bearer ${apiKey}`, "Content-Type": "application/json", }; const options: RequestInit = { method, headers, }; if (body && method !== "GET") { options.body = JSON.stringify(body); } const response = await fetch(`${RETELL_API_BASE}${endpoint}`, options); if (!response.ok) { const errorText = await response.text(); throw new Error(`Retell API error (${response.status}): ${errorText}`); } // Handle 204 No Content if (response.status === 204) { return { success: true }; } return response.json(); }