API reference
Complete reference for the Etlworks AI Agent Scripting API. All endpoints are under /rest/v1/ai-agent/api.
Authentication
All requests require an API key passed in the Authorization header:
Authorization: Bearer YOUR_API_KEY
API keys are generated in the Etlworks UI: Settings → Users → Edit user → API Key.
| Aspect | Details |
|---|---|
| Header | Authorization: Bearer <key> |
| Key format | 256-character alphanumeric string |
| Expiration | Optional (set during generation, or permanent) |
| Permissions | Inherits the generating user's role and tenant scope |
Base URL
https://your-instance.etlworks.com/rest/v1/ai-agent/api
Replace your-instance.etlworks.com with your Etlworks deployment URL. For on-premise installations, use your internal URL.
Error handling
| HTTP status | Meaning | Action |
|---|---|---|
200 | Success (check response body for application-level errors) | Parse response normally |
400 | Bad request — missing required field | Check request body format |
401 | Unauthorized — invalid or missing API key | Check your API key |
403 | Forbidden — AI features disabled for this account | Contact your admin |
404 | Not found — session does not exist | Create a new session |
500 | Internal server error | Retry or contact support |
Application-level errors in 200 responses use this format:
{
"success": false,
"error": "AI usage cap exceeded",
"code": "cap_exceeded"
}
List tools
Returns all available agent tools with their parameter schemas. Use this to discover what tools exist and what arguments they accept.
Headers
Authorization | Bearer <api-key> | Required |
Response
{
"tools": [
{
"name": "search_knowledge_base",
"description": "Search the knowledge base for articles, documentation, and support tickets related to the user's question.",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "The search query"
}
},
"required": ["query"]
},
"agentic": false
}
],
"count": 7
}
| Field | Type | Description |
|---|---|---|
tools[].name | string | Tool identifier for /tools/{name}/execute |
tools[].description | string | What the tool does |
tools[].parameters | object | JSON Schema for the tool's arguments |
tools[].agentic | boolean | If true, calling this tool counts toward billing caps |
count | number | Total number of tools |
Execute tool
Execute a specific tool directly. The request body must match the tool's parameter schema (from GET /tools).
Path parameters
tool_name | string | The tool name (e.g. search_knowledge_base) |
Request body
JSON object matching the tool's parameter schema. Example for search_knowledge_base:
{"query": "how to create a REST API connection"}
Response
{
"tool": "search_knowledge_base",
"result": "Based on the knowledge base:\n\n## Creating a REST API Connection\n...",
"success": true
}
On tool not found:
{
"success": false,
"error": "Tool not found: unknown_tool",
"available_tools": ["search_knowledge_base", "host_cli", "host_list_commands", "..."]
}
Chat (complete response)
Send a message and receive a complete JSON response. The agent may call tools internally to answer your question. A transient session is created automatically.
Request body
{
"message": "How do I set up a daily sync from REST to PostgreSQL?",
"include_tools": true,
"system_prompt": "You are a helpful data integration assistant."
}
| Field | Type | Required | Description |
|---|---|---|---|
message | string | Yes | The user's message |
include_tools | boolean | No | Enable tool use (default: true) |
system_prompt | string | No | Override the default system prompt |
Response
{
"response": "To set up a daily sync from a REST API to PostgreSQL...",
"session_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"tools_used": ["search_knowledge_base"],
"usage": {
"prompt_tokens": 1842,
"completion_tokens": 456,
"model": "gpt-4.1"
}
}
| Field | Type | Description |
|---|---|---|
response | string | The agent's complete response (Markdown) |
session_id | string | Session ID (can be used to continue the conversation) |
tools_used | string[] | Tools the agent called (omitted if none) |
error | string | Error message (only present on failure) |
usage.prompt_tokens | number | Input tokens consumed |
usage.completion_tokens | number | Output tokens generated |
usage.model | string | Model used (e.g. "gpt-4.1") |
Chat (streaming)
Send a message and receive a streaming response via Server-Sent Events. Same request body as /chat. Tokens arrive in real time as they are generated.
Request body
Same as POST /chat.
Response
Content-Type: text/event-stream
data: {"type":"session","session_id":"a1b2c3d4..."}
data: {"type":"phase","phase":"thinking","message":"Reviewing your request..."}
data: {"type":"tool_start","tool":"search_knowledge_base","message":"Searching the knowledge base..."}
data: {"type":"tool_end","tool":"search_knowledge_base"}
data: {"type":"token","content":"To "}
data: {"type":"token","content":"set up "}
data: {"type":"token","content":"a daily sync..."}
data: {"type":"usage","prompt_tokens":1842,"completion_tokens":456,"model":"gpt-4.1"}
data: {"type":"end"}
See SSE event types for the complete event reference.
Create session
Create a new persistent chat session. Use sessions for multi-turn conversations where the agent needs to remember prior context.
Response
{
"session_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"created": true
}
Session chat (complete response)
Send a message within a session and get a complete response. The agent has access to the full conversation history from this session.
Path parameters
session_id | string | Session ID from POST /sessions |
Request body
{
"message": "Now how do I schedule it to run daily?",
"include_tools": true
}
Response
Same format as POST /chat.
Session chat (streaming)
Streaming version of session chat. Returns SSE events. Same format as POST /chat/stream.
Path parameters
session_id | string | Session ID |
Request body
Same as Session chat.
Get session messages
Retrieve the conversation history for a session. Returns user and assistant messages (system and tool messages are excluded).
Path parameters
session_id | string | Session ID |
Response
[
{"role": "user", "content": "How do I create a REST connection?"},
{"role": "assistant", "content": "To create a REST connection, follow these steps..."},
{"role": "user", "content": "Now how do I schedule it?"},
{"role": "assistant", "content": "To schedule the flow..."}
]
SSE event types
Streaming endpoints return Server-Sent Events. Each event is a JSON object on a data: line:
| Type | Fields | Description |
|---|---|---|
session |
session_id |
First event. Contains the session ID for this request. |
phase |
phase, message |
Agent processing phase. Phases: thinking, analyzing, preparing. |
token |
content |
A text token from the LLM. Concatenate all tokens to build the full response. |
tool_start |
tool, message |
A tool has started executing. tool is the tool name. |
tool_end |
tool |
A tool has finished executing. |
usage |
prompt_tokens, completion_tokens, model |
Token usage for this LLM call. May appear multiple times if tools triggered additional LLM calls. |
end |
— | Response is complete. Close the connection. |
error |
message, retryable |
An error occurred. If retryable is true, the client may retry the request. |
Each event is a line starting with data: followed by a JSON object, terminated by two newlines (\n\n). Ignore blank lines and lines starting with : (SSE comments).
Tool reference
search_knowledge_base
Free Search KB articles, documentation, support tickets, and templates.
{"query": "how to create a REST API connection"}
search_templates
Free Search for flow and connection templates by topic or integration name.
{"query": "salesforce to database"}
create_support_ticket
Free Create a Zendesk support ticket.
{"subject": "Need help with REST connection", "description": "I am getting a 401 error when...", "user_email": "user@company.com"}
host_list_commands
Billed List all available CLI commands. Takes no arguments.
{}
host_cli
Billed Execute a CLI command on the Etlworks host.
{"command": "list connections"}
import_template
Billed Import a flow or connection template. Supports preview mode.
{"template_id": 42, "mode": "standard"}
Modes: standard (original flow type) or composer (visual canvas).
Billing & usage caps
Free monthly allowance
Every Etlworks subscription includes a free monthly agentic usage allowance of up to $20 (exact amount depends on your subscription tier). This covers both the web UI chat and API usage. Non-agentic tools (knowledge base search, template search, support tickets) are always free and unlimited.
API requests consume the same billing resources as the Etlworks chat UI:
- Free tools (
agentic: false) — knowledge base searches, template searches, and support tickets do not count toward usage caps. Always free, no limits. - Billed tools (
agentic: true) — CLI commands and template imports count toward your monthly allowance. - Chat endpoints — LLM token usage is tracked and counts toward your monthly allowance. If agentic tools are called during a chat, those are billed too.
- Cap exceeded — when the monthly allowance is used up, chat responses return
"code": "cap_exceeded". Free tools continue to work. You can recharge via the AI Wallet or bring your own API key (see below).
All API calls are tracked under the user who generated the API key. Usage counts toward the same monthly caps as the web UI. Monitor your usage on the AI Agent dashboard in Etlworks.
Bring your own OpenAI API key
If you want to bypass Etlworks billing entirely, you can configure your own OpenAI API key. When a custom key is set, all LLM calls go directly to OpenAI using your key, and agentic usage does not count toward Etlworks monthly caps.
This is ideal for:
- High-volume API integrations that exceed the free monthly allowance
- Teams that prefer to manage their own OpenAI billing
- Development and testing without worrying about usage limits
Setting your API key
Via the Etlworks UI:
- Log in to your Etlworks instance
- Open the AI Agent chat panel
- Click the settings icon in the chat header
- Enter your OpenAI API key and save
Via the REST API:
# Set your own OpenAI API key
curl -s "$ETLWORKS_URL/rest/v1/ai-agent/api-key" \
-H "Authorization: Bearer $ETLWORKS_API_KEY" \
-H "Content-Type: application/json" \
-X POST \
-d '{"api_key": "sk-your-openai-api-key"}'
# Check if a key is configured
curl -s "$ETLWORKS_URL/rest/v1/ai-agent/api-key" \
-H "Authorization: Bearer $ETLWORKS_API_KEY"
# Remove your custom key (reverts to Etlworks-managed billing)
curl -s "$ETLWORKS_URL/rest/v1/ai-agent/api-key/delete" \
-H "Authorization: Bearer $ETLWORKS_API_KEY" \
-X POST
Shared environments: Tenant admins can set a key for their tenant. All users in that tenant will use it.
Dedicated environments: Super admins set a global key for the entire instance.
When a custom key is active, the usage type changes to "own_key" and Etlworks caps do not apply.
With the Etlworks-managed key, you get up to $20/month of free agentic usage (depending on your subscription tier), plus wallet top-ups if needed. With your own key, you pay OpenAI directly at their standard rates — which can be more economical for heavy API usage.