Skip to main content
POST
/
v1
/
custom_functions
/
generate
Generate Custom Function
curl --request POST \
  --url https://api.example.com/v1/custom_functions/generate \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '
{
  "query": "",
  "user_function": "",
  "import_curl": ""
}
'
{
  "custom_function": "<string>"
}
AI-generate a custom function from a natural language description. Provide a description of what the function should do, and optionally provide existing code to improve or a cURL command to convert into a function.

Request Body

query
string
Natural language description of what the function should do (e.g., “fetch stock prices from Yahoo Finance”)
user_function
string
Existing Python code to improve or refactor
import_curl
string
A cURL command to convert into a custom function

Response

custom_function
string
The generated Python source code ready to use with Create Custom Function

Example Request

curl -X POST "https://api.xpander.ai/v1/custom_functions/generate" \
  -H "Content-Type: application/json" \
  -H "x-api-key: <your-api-key>" \
  -d '{"query": "Create a function that fetches the current Bitcoin price from CoinGecko API"}'

Notes

  • The generated code includes a xpander_run_action(...) entry point
  • Review the generated code before creating the function
  • You can provide user_function to improve existing code, or import_curl to convert a cURL command

Authorizations

x-api-key
string
header
required

API Key for authentication

Body

application/json

Request model for AI-generating a custom function from a description.

Provide a natural language description of what you need, and the AI will generate the Python source code with proper xpander_run_action signature.

query
string | null
default:""

Natural language description of what the function should do. Examples: 'Calculate compound interest given principal, rate, and years', 'Parse a CSV string and return the headers and first 5 rows'.

user_function
string | null
default:""

Optional existing source code to improve or modify. The AI will use this as a starting point.

import_curl
string | null
default:""

Optional cURL command to convert into a custom function. The AI will parse the cURL and generate a function that makes the equivalent HTTP request.

Response

Successful Response

Response from the AI custom function generator.

custom_function
string
required

Generated Python source code defining xpander_run_action(...).