---
title: "Generate Custom Function"
method: POST
path: "/v1/custom_functions/generate"
tags: ["API v1", "Custom Functions"]
---

# Generate Custom Function

`POST /v1/custom_functions/generate`

## Request

- Base URL: `https://api.xpander.ai` (the document declares no server; this is the origin it was published from)
- URL: `https://api.xpander.ai/v1/custom_functions/generate`
- Auth: API key in header `x-api-key`

AI-generate a custom function from a natural language description. Provide a 'query' describing what the function should do, and optionally 'user_function' (existing code to improve) or 'import_curl' (a cURL command to convert into a function). Returns the generated Python source code.

## Request body

- GenerateCustomFunctionRequest: 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, nullable: 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, nullable: Optional existing source code to improve or modify. The AI will use this as a starting point.
  - `import_curl` string, nullable: 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 `200`

Successful Response

- GenerateCustomFunctionResponse: Response from the AI custom function generator.
  - `custom_function` string, required: Generated Python source code defining xpander_run_action(...).

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/xpander/apis/xpander-ai-api-service.md) - [All operations](https://skmtc.dev/xpander/apis/xpander-ai-api-service/llms.txt) - [OpenAPI document](https://skmtc.dev/xpander/apis/xpander-ai-api-service/revisions/725c0066d5df?raw)
