Skip to main content
POST
/
v1
/
custom_functions
/
generate
Generate Custom Function
curl --request POST \
  --url https://api.xpander.ai/v1/custom_functions/generate \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '
{
  "query": "",
  "user_function": "",
  "import_curl": ""
}
'
import requests

url = "https://api.xpander.ai/v1/custom_functions/generate"

payload = {
"query": "",
"user_function": "",
"import_curl": ""
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({query: '', user_function: '', import_curl: ''})
};

fetch('https://api.xpander.ai/v1/custom_functions/generate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.xpander.ai/v1/custom_functions/generate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'query' => '',
'user_function' => '',
'import_curl' => ''
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.xpander.ai/v1/custom_functions/generate"

payload := strings.NewReader("{\n \"query\": \"\",\n \"user_function\": \"\",\n \"import_curl\": \"\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.xpander.ai/v1/custom_functions/generate")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"\",\n \"user_function\": \"\",\n \"import_curl\": \"\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.xpander.ai/v1/custom_functions/generate")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"query\": \"\",\n \"user_function\": \"\",\n \"import_curl\": \"\"\n}"

response = http.request(request)
puts response.read_body
{
  "custom_function": "<string>"
}
{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<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(...).