I've used the API reference, and asked Ivy to provide an example - The function below I use to create the llm:
def _create_retell_llm(client, model_name: str, prompt: str, webhook_url: str) -> str:
final_prompt = (prompt or "").strip()
final_prompt += "\n\nALWAYS call the sendMail function on every call."
custom_function = {
"type": "custom_function",
"name": "sendMail",
"description": "Send caller details to a webhook for email delivery.",
"url": webhook_url,
"method": "POST",
"parameters": {
"type": "object",
"properties": {
"name": {"type": "string", "description": "The caller's full name"},
"notes": {"type": "string", "description": "Any additional message"},
"contact": {"type": "string", "description": "Phone or email"},
},
"required": ["name", "contact", "notes"],
},
}
try:
llm_resp = client.llm.create(
start_speaker="user",
model=model_name,
general_prompt=final_prompt,
general_tools=[custom_function],
)
except Exception as e:
if "must be equal to one of the allowed values" in str(e):
current_app.logger.warning("custom_function")
# Retry creating LLM without tools
llm_resp = client.llm.create(
start_speaker="user",
model=model_name,
general_prompt=final_prompt,
)
else:
raise
data = _to_dict(llm_resp) or {}
llm_id = data.get("llm_id") or data.get("id")
if not llm_id:
raise RuntimeError(f"Retell LLM create returned no id. Raw: {data!r}")
return llm_id