https://retellai.com/?utm_source=discord&utm_medium=seo logo
Creating custom functions with python SDK 4.54
# ❓・bug-report
r
Constantly being returned error code 400 when trying to create a custom function, error log: Error creating agent with Retell: Error code: 400 - {'error_message': "request/body/general_tools/0/type must be equal to one of the allowed values: end_call, request/body/general_tools/0 must have required property 'transfer_destination', request/body/general_tools/0 must have required property 'cal_api_key', request/body/general_tools/0 must have required property 'cal_api_key', request/body/general_tools/0 must have required property 'agent_id', request/body/general_tools/0/type must be equal to one of the allowed values: press_digit, request/body/general_tools/0 must have required property 'sms_content', request/body/general_tools/0 must have required property 'speak_after_execution', request/body/general_tools/0 must have required property 'variables', request/body/general_tools/0/type must be equal to one of the allowed values: mcp, request/body/general_tools/0 must match exactly one schema in oneOf"} I am passing through "custom_function" as the type.
@User Can someone review ? Does this functionality need to be enabled for the workspace?
c
are you creating it via api?
r
I am using the python SDK - version 4.54
It's the client.llm.create API call that is returning the error logs I provided in the report
@User any idea what the issue is here?
@User team, is there any update on this? Completely stuck with this issue
c
i would have to see your code in order to diagnose the issue, i’m unable to reproduce this error
without that the best i can do is give you examples and the api reference
r
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
The call it from another code block in a try method: try: llm_id = _create_retell_llm( client=retell, model_name="gpt-4.1", prompt=prompt, webhook_url=webhook_url, ) agent_resp = retell.agent.create( response_engine={ "type": "retell-llm", "llm_id": llm_id, }, voice_id=voice_id, agent_name=name, )
@Colin - Integrations @ Retell AI my code is above, I believe it's aligned to the documentation
a
Type should be custom
r
custom, not custom function ?
a
Yes
r
I checked this with Ivy in the support questions channel
I will update the code and try again