AI Agent API

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:

HTTP
Authorization: Bearer YOUR_API_KEY

API keys are generated in the Etlworks UI: Settings → Users → Edit user → API Key.

AspectDetails
HeaderAuthorization: Bearer <key>
Key format256-character alphanumeric string
ExpirationOptional (set during generation, or permanent)
PermissionsInherits the generating user's role and tenant scope

Base URL

HTTP
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 statusMeaningAction
200Success (check response body for application-level errors)Parse response normally
400Bad request — missing required fieldCheck request body format
401Unauthorized — invalid or missing API keyCheck your API key
403Forbidden — AI features disabled for this accountContact your admin
404Not found — session does not existCreate a new session
500Internal server errorRetry or contact support

Application-level errors in 200 responses use this format:

JSON
{
  "success": false,
  "error": "AI usage cap exceeded",
  "code": "cap_exceeded"
}

List tools

GET /tools

Returns all available agent tools with their parameter schemas. Use this to discover what tools exist and what arguments they accept.

Headers

AuthorizationBearer <api-key>Required

Response

JSON
{
  "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
}
FieldTypeDescription
tools[].namestringTool identifier for /tools/{name}/execute
tools[].descriptionstringWhat the tool does
tools[].parametersobjectJSON Schema for the tool's arguments
tools[].agenticbooleanIf true, calling this tool counts toward billing caps
countnumberTotal number of tools

Execute tool

POST /tools/{tool_name}/execute

Execute a specific tool directly. The request body must match the tool's parameter schema (from GET /tools).

Path parameters

tool_namestringThe tool name (e.g. search_knowledge_base)

Request body

JSON object matching the tool's parameter schema. Example for search_knowledge_base:

JSON
{"query": "how to create a REST API connection"}

Response

JSON
{
  "tool": "search_knowledge_base",
  "result": "Based on the knowledge base:\n\n## Creating a REST API Connection\n...",
  "success": true
}

On tool not found:

JSON
{
  "success": false,
  "error": "Tool not found: unknown_tool",
  "available_tools": ["search_knowledge_base", "host_cli", "host_list_commands", "..."]
}

Chat (complete response)

POST /chat

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

JSON
{
  "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."
}
FieldTypeRequiredDescription
messagestringYesThe user's message
include_toolsbooleanNoEnable tool use (default: true)
system_promptstringNoOverride the default system prompt

Response

JSON
{
  "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"
  }
}
FieldTypeDescription
responsestringThe agent's complete response (Markdown)
session_idstringSession ID (can be used to continue the conversation)
tools_usedstring[]Tools the agent called (omitted if none)
errorstringError message (only present on failure)
usage.prompt_tokensnumberInput tokens consumed
usage.completion_tokensnumberOutput tokens generated
usage.modelstringModel used (e.g. "gpt-4.1")

Chat (streaming)

POST /chat/stream

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

HTTP
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

POST /sessions

Create a new persistent chat session. Use sessions for multi-turn conversations where the agent needs to remember prior context.

Response

JSON
{
  "session_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "created": true
}

Session chat (complete response)

POST /sessions/{session_id}/chat

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_idstringSession ID from POST /sessions

Request body

JSON
{
  "message": "Now how do I schedule it to run daily?",
  "include_tools": true
}

Response

Same format as POST /chat.

Session chat (streaming)

POST /sessions/{session_id}/chat/stream

Streaming version of session chat. Returns SSE events. Same format as POST /chat/stream.

Path parameters

session_idstringSession ID

Request body

Same as Session chat.

Get session messages

GET /sessions/{session_id}/messages

Retrieve the conversation history for a session. Returns user and assistant messages (system and tool messages are excluded).

Path parameters

session_idstringSession ID

Response

JSON
[
  {"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:

TypeFieldsDescription
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.
Parsing SSE

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.

JSON
{"query": "how to create a REST API connection"}

search_templates

Free Search for flow and connection templates by topic or integration name.

JSON
{"query": "salesforce to database"}

create_support_ticket

Free Create a Zendesk support ticket.

JSON
{"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.

JSON
{}

host_cli

Billed Execute a CLI command on the Etlworks host.

JSON
{"command": "list connections"}

import_template

Billed Import a flow or connection template. Supports preview mode.

JSON
{"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:

Usage tracking

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:

Setting your API key

Via the Etlworks UI:

  1. Log in to your Etlworks instance
  2. Open the AI Agent chat panel
  3. Click the settings icon in the chat header
  4. Enter your OpenAI API key and save

Via the REST API:

Shell
# 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
Key scoping

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.

Cost comparison

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.