denghuichao
08/08/2025, 10:20 AMAI Evy
08/08/2025, 10:20 AMAI Evy
08/08/2025, 10:20 AMAI Evy
08/08/2025, 10:20 AMAI Evy
08/08/2025, 10:20 AMdenghuichao
08/08/2025, 10:21 AMdenghuichao
08/08/2025, 10:22 AMAI Evy
08/08/2025, 10:22 AMAI Evy
08/08/2025, 10:22 AMllm_id field [(1) ]() :
javascript
const llmResponse = await client.llm.create() ;
console.log(llmResponse.llm_id) ;
The response will contain the unique llm_id like "oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD" .
## 2. List All LLMs
You can retrieve all your existing LLMs using the list endpoint [(2) ]() :
javascript
import Retell from 'retell-sdk';
const client = new Retell({
apiKey: 'YOUR_RETELL_API_KEY',
}) ;
const llmResponses = await client.llm.list() ;
console.log(llmResponses) ;
This returns an array of all your LLMs, each containing their llm_id .
## 3. Retrieve Specific LLM
If you know the LLM ID, you can retrieve its details [(3) ]() :
javascript
import Retell from 'retell-sdk';
const client = new Retell({
apiKey: 'YOUR_RETELL_API_KEY',
}) ;
const llmResponse = await client.llm.retrieve('16b980523634a6dc504898cda492e939') ;
console.log(llmResponse.llm_id) ;
In your code example, you're already accessing it correctly with newModel.llm_id after the create call [(1) ]() .AI Evy
08/08/2025, 10:22 AMAI Evy
08/08/2025, 10:22 AMdenghuichao
08/08/2025, 10:24 AMAI Evy
08/08/2025, 10:24 AMAI Evy
08/08/2025, 10:24 AMjavascript
import Retell from 'retell-sdk';
const client = new Retell({
apiKey: 'YOUR_RETELL_API_KEY',
}) ;
const agentResponse = await client.agent.retrieve('16b980523634a6dc504898cda492e939') ;
console.log(agentResponse.agent_id) ;
The response will include the response_engine object which contains the llm_id :
javascript
{
"response_engine": {
"type": "retell-llm",
"llm_id": "llm_234sdertfsdsfsdf",
"version": 0
}
}
You can then extract the LLM ID with agentResponse.response_engine.llm_id .
## List All Agents to Find LLM IDs
You can also list all your agents to see which LLM IDs are being used [(2) ]() :
javascript
import Retell from 'retell-sdk';
const client = new Retell({
apiKey: 'YOUR_RETELL_API_KEY',
}) ;
const agentResponse = await client.agent.list() ;
This will return an array of all agents, each containing their response_engine with the associated llm_id .AI Evy
08/08/2025, 10:24 AMAI Evy
08/08/2025, 10:24 AMdenghuichao
08/08/2025, 10:26 AMAI Evy
08/08/2025, 10:26 AMAI Evy
08/08/2025, 10:26 AMjavascript
import Retell from 'retell-sdk';
const client = new Retell({
apiKey: 'YOUR_RETELL_API_KEY',
}) ;
// Try to get existing LLM ID from first agent
let llm_id;
try {
const agentResponse = await client.agent.list() ;
if (agentResponse.results && agentResponse.results.length > 0) {
// Get LLM ID from first existing agent
llm_id = agentResponse.results[0].response_engine.llm_id;
console.log(`Using existing LLM ID: ${llm_id}`) ;
} else {
// No agents exist, create new LLM
const newModel = await client.llm.create({
model: "gpt-4o",
general_prompt: RETELL_AGENT_GENERAL_PROMPT,
general_tools: [
{
type: "end_call",
name: "end_call_1",
description: "End the call if the user uses goodbye phrases such as 'bye,' 'goodbye,' or 'have a nice day.'",
},
],
}) ;
llm_id = newModel.llm_id;
console.log(`Created new LLM with ID: ${llm_id}`) ;
}
} catch (error) {
console.error("Error getting LLM ID:", error) ;
throw error;
}
// Now create agent with the LLM ID
const newAgent = await client.agent.create({
response_engine: { llm_id: llm_id, type: "retell-llm" },
voice_id: body.voice_id,
agent_name: body.name,
}) ;
[(1) ]()
This code first attempts to list existing agents . If agents exist, it extracts the llm_id from the first agent's response_engine . If no agents exist, it creates a new LLM and uses that ID for the new agent [(2) ]() .AI Evy
08/08/2025, 10:26 AMAI Evy
08/08/2025, 10:26 AMAI Evy
08/08/2025, 10:27 AMdenghuichao
08/08/2025, 10:37 AMUsing existing LLM ID: ${llm_id});
}
Property 'llm_id' does not exist on type 'ResponseEngineRetellLm | ResponseEngineCustomLm | ResponseEngineConversationFlow'.
Property 'llm_id' does not exist on type 'ResponseEngineCustomLm'.AI Evy
08/08/2025, 10:37 AMAI Evy
08/08/2025, 10:37 AMresponse_engine can be one of multiple types, and not all types have the llm_id property [(1) ]() . You need to check the type first before accessing llm_id .
Here's the corrected code that handles the different response engine types :
javascript
let llm_id;
const agentResponse = await retellClient.agent.list() ;
if (agentResponse && agentResponse.length > 0) {
const responseEngine = agentResponse[0].response_engine;
// Check if it's a retell-llm type before accessing llm_id
if (responseEngine.type === "retell-llm") {
llm_id = responseEngine.llm_id;
console.log(`Using existing LLM ID: ${llm_id}`) ;
} else {
console.log("First agent doesn't use retell-llm, creating new LLM") ;
// Create new LLM logic here
}
}
The response engine can be one of three types according to the documentation :
- retell-llm (which has llm_id)
- custom-llm (which doesn't have llm_id)
- conversation-flow (which doesn't have llm_id)
By checking responseEngine.type === "retell-llm" first, TypeScript will know that the object has the llm_id property .AI Evy
08/08/2025, 10:37 AMAI Evy
08/08/2025, 10:37 AMdenghuichao
08/08/2025, 10:38 AMAI Evy
08/08/2025, 10:38 AMAI Evy
08/08/2025, 10:38 AMjavascript
import Retell from 'retell-sdk';
const client = new Retell({
apiKey: 'YOUR_RETELL_API_KEY',
}) ;
const agentResponses = await client.agent.list() ;
[(1) ]()
Then filter for the first agent with a retell-llm response engine:
javascript
let llm_id;
const agentResponse = await retellClient.agent.list() ;
if (agentResponse && agentResponse.length > 0) {
// Find the first agent with retell-llm response engine
const retellLlmAgent = agentResponse.find(agent =>
agent.response_engine.type === "retell-llm"
) ;
if (retellLlmAgent) {
llm_id = retellLlmAgent.response_engine.llm_id;
console.log(`Using existing LLM ID: ${llm_id}`) ;
} else {
console.log("No agents with retell-llm found, creating new LLM") ;
// Create new LLM logic here
}
}
The response structure shows that agents can have different response engine types, and only the retell-llm type contains the llm_id field . The find() method will return the first agent that matches the condition, or undefined if none are found.AI Evy
08/08/2025, 10:39 AMAI Evy
08/08/2025, 10:39 AMdenghuichao
08/08/2025, 10:40 AMAI Evy
08/08/2025, 10:40 AMAI Evy
08/08/2025, 10:40 AMjavascript
let llm_id;
const agentResponse = await retellClient.agent.list() ;
if (agentResponse && agentResponse.length > 0) {
// Find the first agent with retell-llm response engine
const retellLlmAgent = agentResponse.find(agent =>
agent.response_engine.type === "retell-llm"
) ;
if (retellLlmAgent) {
// Type assertion/cast to ResponseEngineRetellLm
const retellLlmEngine = retellLlmAgent.response_engine as ResponseEngineRetellLm;
llm_id = retellLlmEngine.llm_id;
console.log(`Using existing LLM ID: ${llm_id}`) ;
} else {
console.log("No agents with retell-llm found, creating new LLM") ;
// Create new LLM logic here
}
}
[(1) ]()
Alternatively, you can use a type guard approach:
javascript
// Type guard function
function isRetellLlmEngine(engine: any) : engine is ResponseEngineRetellLm {
return engine.type === "retell-llm";
}
let llm_id;
const agentResponse = await retellClient.agent.list() ;
if (agentResponse && agentResponse.length > 0) {
const firstAgent = agentResponse[0];
if (isRetellLlmEngine(firstAgent.response_engine) ) {
// TypeScript now knows this is ResponseEngineRetellLm
llm_id = firstAgent.response_engine.llm_id;
console.log(`Using existing LLM ID: ${llm_id}`) ;
}
}
Both approaches will resolve the TypeScript error by ensuring you're working with the correct response engine type that contains the llm_id property.AI Evy
08/08/2025, 10:41 AMAI Evy
08/08/2025, 10:41 AMdenghuichao
08/08/2025, 10:42 AMAI Evy
08/08/2025, 10:42 AMAI Evy
08/08/2025, 10:42 AMResponseEngineRetellLm, you'll need to import it from the Retell SDK types [(1) ]() :
typescript
import Retell, { ResponseEngineRetellLm } from 'retell-sdk';
The TypeScript SDK provides access to all the request and response types, including ResponseEngineRetellLm . You can then use it for type casting as discussed in your previous message:
typescript
const retellLlmEngine = retellLlmAgent.response_engine as ResponseEngineRetellLm;
llm_id = retellLlmEngine.llm_id;
This approach gives you proper TypeScript type safety when working with the response engine that contains the llm_id property .AI Evy
08/08/2025, 10:42 AMAI Evy
08/08/2025, 10:42 AM