FlowGent API Reference

Learn how to integrate FlowGent's powerful AI agents into your applications using our REST API.

Introduction

Welcome to the FlowGent API documentation. This API allows you to integrate FlowGent's powerful AI agent capabilities into your own applications.

Base URL

https://flowgent.ai/api/public/

What You Can Do

With the FlowGent API, you can:

  • Create and configure AI agents
  • Send messages to agents and receive responses
  • Monitor agent activity and performance
  • Send templated whatsapp messages

Authentication

Authentication with the FlowGent API is done using API keys. Your API key should be included in the Authorization header of all requests.

API Keys

You can create API keys in the FlowGent Settings. API keys are sensitive credentials and should be kept secure.

Authorization Header

Authorization: YOUR_API_KEY

Security Notice

Never expose your API keys in client-side code or commit them to version control. Consider using environment variables or a secure secrets management system.

Example Request

curl -X GET \
  -H "Content-Type: application/json" \
  -H "Authorization: YOUR_API_KEY" \
  https://flowgent.ai/api/public/agent

[POST] Chat

Endpoint

/api/public/agent/:agent_id/chat

Description

Send messages to an agent and get a response. This endpoint supports both synchronous and asynchronous processing through an optional callback URL.

Authentication

Requires an API key in the Authorization header.

Authorization: YOUR_API_KEY

Path Parameters

ParameterTypeDescription
agent_idstringThe agent&aposs unique identifier

Request Body

The messages field can be provided in three different formats:

Option 1: Single message string

{
  "messages": "Hello, I have a question about my order",
  "thread_id": "thread_123456",  // Optional
  "callback_url": "https://your-domain.com/webhook"  // Optional
}

Option 2: Single message object

{
  "messages": {
    "role": "user",
    "content": "Hello, I have a question about my order"
  },
  "thread_id": "thread_123456",  // Optional
  "callback_url": "https://your-domain.com/webhook"  // Optional
}

Option 3: Array of message objects

{
  "messages": [
    {
      "role": "user",
      "content": "Hello, I have a question about my order"
    }
  ],
  "thread_id": "thread_123456",  // Optional
  "callback_url": "https://your-domain.com/webhook"  // Optional
}
ParameterTypeRequiredDescription
messagesstring | object | arrayYesCan be a string, a message object, or an array of message objects
thread_idstringNoOptional thread ID for continuing a conversation
callback_urlstringNoURL to receive the response asynchronously

Response Structures

⚠️ Important: Always Check Response Body

This endpoint may return HTTP 200 status even when there are errors in the execution. Always check the response body forstatusCode and the results of any tool executions.

Success Response (200 OK)

{
  "statusCode": 200,
  "body": {
    "agent_id": "agent_123abc",
    "conversation_history": [
      {
        "role": "user",
        "content": "Hello, I have a question about my order"
      },
      {
        "role": "assistant",
        "content": "I'd be happy to help with your order. Could you please provide your order number?"
      }
    ],
    "metadata": {
      "id": "meta_xyz789",
      "model": "gpt-4",
      "timestamp": "2024-03-21T14:30:00Z",
      "tool_calls": {},
      "execution_time": 2500,
      "used_credits": 1,
      "thread_id": "thread_123456"
    }
  }
}

No Credits Available (402 Payment Required)

{
  "statusCode": 402,
  "body": {
    "agent_id": "agent_123abc",
    "message": "No credits available",
    "error": "No credits available"
  }
}

Service Temporarily Unavailable (503)

{
  "statusCode": 503,
  "body": {
    "agent_id": "agent_123abc",
    "message": "Service temporarily unavailable",
    "error": "AI provider is currently experiencing high traffic"
  }
}

Internal Server Error (500)

{
  "statusCode": 500,
  "body": {
    "error": "An unexpected error occurred while processing your request"
  }
}

Asynchronous Response

When using the callback_url parameter, you'll receive an immediate acknowledgement:

{
  "message": "Request accepted and being processed asynchronously",
  "status": "processing"
}

[GET] Usage

Endpoint

/api/public/agent/:agent_id/usage

Description

Get credit usage statistics for an agent. By default, returns data for the last 7 days (ending yesterday). You can optionally specify a custom date range using query parameters.

Note: Usage tracking is only active from May 28, 2025 onwards. Data before this date will show 0 credits used.

Authentication

Requires an API key in the Authorization header.

Authorization: YOUR_API_KEY

Path Parameters

ParameterTypeDescription
agent_idstringThe agent's unique identifier

Query Parameters

Optional parameters to specify a custom date range. If not provided, defaults to the last 7 days ending yesterday.

ParameterTypeRequiredDescription
start_datestringNo*Start date for the query range in YYYY-MM-DD format
end_datestringNo*End date for the query range in YYYY-MM-DD format

* If only start_date is provided, yesterday will be used as end_date. If only end_date is provided, an error will be returned. The date range cannot exceed 31 days, and the end_date cannot be today or in the future (data is only available up to yesterday).

Example Requests

// Default (last 7 days)
GET /api/public/agent/66a72b17-cb03-4397-ab2a-1eef13847737/usage

// Custom date range (both dates)
GET /api/public/agent/66a72b17-cb03-4397-ab2a-1eef13847737/usage?start_date=2025-05-20&end_date=2025-05-26

// Start date only (end_date will be yesterday)
GET /api/public/agent/66a72b17-cb03-4397-ab2a-1eef13847737/usage?start_date=2025-05-20

Response

{
  "agent_id": "66a72b17-cb03-4397-ab2a-1eef13847737",
  "time_range": {
    "start": "2025-05-20T00:00:00.000Z",
    "end": "2025-05-26T23:59:59.999Z"
  },
  "usage": {
    "total_credits_used": 3,
    "daily_breakdown": [
      {
        "date": "2025-05-26",
        "credits_used": 1
      },
      {
        "date": "2025-05-25",
        "credits_used": 0
      },
      {
        "date": "2025-05-24",
        "credits_used": 2
      },
      {
        "date": "2025-05-23",
        "credits_used": 0
      },
      {
        "date": "2025-05-22",
        "credits_used": 0
      },
      {
        "date": "2025-05-21",
        "credits_used": 0
      },
      {
        "date": "2025-05-20",
        "credits_used": 0
      }
    ]
  },
  "note": "Endpoint active from 28 May 2025 onwards"
}
FieldTypeDescription
agent_idstringThe agent's unique identifier
time_rangeobjectStart and end timestamps for the queried period
usage.total_credits_usednumberTotal credits consumed in the time period
usage.daily_breakdownarrayDaily credit usage breakdown, sorted by date (newest first)
daily_breakdown[].datestringDate in YYYY-MM-DD format
daily_breakdown[].credits_usednumberCredits consumed on this specific date
notestringOptional note about data availability (appears when querying dates before May 28, 2025)

Error Responses

// Missing API Key (401)
{
  "error": "API key is required",
  "message": "Please provide an API key in the Authorization header"
}

// Invalid API Key (401)
{
  "error": "Invalid API key",
  "message": "The provided API key is not valid"
}

// Access Denied (403)
{
  "error": "Access denied",
  "message": "This agent does not belong to your organisation"
}

// Invalid Agent ID (400)
{
  "error": "agent_id is required and must be a non-empty string"
}

// Missing Start Date When End Date Provided (400)
{
  "error": "Invalid date range",
  "message": "start_date is required when end_date is provided (format: YYYY-MM-DD)"
}

// Invalid Date Format (400)
{
  "error": "Invalid date format",
  "message": "Dates must be in YYYY-MM-DD format"
}

// Invalid Dates (400)
{
  "error": "Invalid dates",
  "message": "Provided dates are not valid"
}

// Start Date After End Date (400)
{
  "error": "Invalid date range",
  "message": "start_date must not be after end_date"
}

// End Date Too Recent (400)
{
  "error": "Invalid end date",
  "message": "end_date cannot be today or in the future. Data is only available up to yesterday."
}

// Date Range Too Large (400)
{
  "error": "Date range too large",
  "message": "Date range cannot exceed 31 days"
}

// Internal Server Error (500)
{
  "error": "Internal server error"
}

Notes

  • Default behavior: Without query parameters, returns the last 7 days ending yesterday (UTC)
  • Custom date ranges: Use start_date and/or end_date parameters in YYYY-MM-DD format. If only start_date is provided, yesterday is used as end_date
  • Date range limits: Maximum 31 days, end_date cannot be today or in the future
  • Data completeness: All days in the range are included, even with 0 usage
  • Credit counting: Only positive credit transactions (actual usage) are counted
  • Sort order: Results are sorted by date in descending order (newest first)
  • Data availability: Usage tracking is only active from May 28, 2025 onwards - dates before this will show 0 usage
  • Historical data note: A "note" field is included when the queried range includes dates before May 28, 2025

[POST] WhatsApp template

Endpoint

/api/public/agent/:agent_id/waba

Description

Send WhatsApp templates using your agent through the WhatsApp Business API.

Authentication

Requires an API key in the Authorization header.

Authorization: YOUR_API_KEY

Path Parameters

ParameterTypeDescription
agent_idstringThe agent's unique identifier

Request Body

{
  "recipient_phone_number": "31612345678",
  "template_name": "order_update",
  "language": "en_US",
  "customer_name": "John Doe",
  "parameters": [
    {
      "type": "header",
      "parameters": [
        {
          "type": "image",
          "image": {
            "link": "https://whatsapp_image_template"
          }
        }
      ]
    },
    {
      "type": "body",
      "parameters": [
        {
          "type": "text",
          "text": "ABC123"
        },
        {
          "type": "text",
          "text": "Shipped"
        }
      ]
    }
  ]
}
ParameterTypeRequiredDescription
recipient_phone_numberstringYesRecipient's phone number with country code
template_namestringYesName of the WhatsApp template to use
languagestringYesLanguage code (e.g., en_US, en, nl_NL)
customer_namestringNoName of the customer (for new customers)
parametersarrayNoTemplate parameters for dynamic content

For detailed information about formatting template parameters, please refer to the WhatsApp Cloud API documentation.

Example Response

{
  "messaging_product": "whatsapp",
  "contacts": [{
      "input": "PHONE_NUMBER",
      "wa_id": "WHATSAPP_ID"
    }],
  "messages": [{
      "id": "wamid.ID"
    }]
}

Error Responses

{
  "error": "Invalid API key",
  "message": "The provided API key is not valid"
}

{
  "error": "Missing required fields",
  "message": "recipient_phone_number and template_name are required"
}

{
  "error": "WhatsApp connection not found",
  "message": "No WhatsApp connection found for this agent"
}

{
  "error": "Internal server error"
}

[POST] Add Knowledge

Endpoint

/api/public/knowledge

Description

Create a new knowledge item and link it to the provided agent(s).

Authentication

Requires an API key in the Authorization header.

Authorization: YOUR_API_KEY

Request Body

{
  "content": "string",
  "name": "string",
  "agent_ids": ["uuid"] | "uuid",
  "description_to_index_on": "string"  // Optional
}
ParameterTypeRequiredDescription
contentstringYesThe knowledge content to store and index (max 4000 characters)
namestringNoDisplay name for the knowledge item
agent_idsarray | stringYesAgent IDs to link this knowledge to (single string or array)
description_to_index_onstringNoCustom description to embed instead of content

Example Request

curl -X POST "https://flowgent.ai/api/public/knowledge" \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Our premium support includes 24/7 chat, phone support, and dedicated account management.",
    "name": "Premium Support Information",
    "agent_ids": ["agent-uuid-1"],
    "description_to_index_on": "Premium support features and benefits"
  }'

Response

{
  "id": "item-uuid-123",
  "name": "Premium Support Information",
  "created_at": "2023-12-29T10:00:00Z",
  "updated_at": "2023-12-29T10:00:00Z",
  "source": "api",
  "linked_agents": ["agent-uuid-1"]
}

Error Responses

// Missing API Key (401)
{
  "error": "API key is required",
  "message": "Please provide an API key in the Authorization header"
}

// Invalid API Key (401)
{
  "error": "Invalid API key",
  "message": "The provided API key is not valid"
}

// Missing Content (400)
{
  "error": "content is required and must be a non-empty string"
}

// Missing Agent IDs (400)
{
  "error": "agent_ids is required and must be a non-empty string or array"
}

// Content Too Long (400)
{
  "error": "Content exceeds character limit",
  "message": "The content field must be 4000 characters or less."
}

// Invalid Agent ID (403)
{
  "error": "Access denied",
  "message": "One or more agents do not belong to your organisation"
}

// Usage Limit Reached (402)
{
  "error": "Usage limit reached",
  "message": "You have reached the maximum number of items in one of your knowledge bases. Please upgrade your plan to add more items.",
  "minimalPlan": "..."
}

// Internal Server Error (500)
{
  "error": "Internal server error"
}

[GET] List Knowledge

Endpoint

/api/public/knowledge

Description

Retrieve a paginated list of knowledge items created via API for your organization. Optionally filter by a specific agent.

Authentication

Requires an API key in the Authorization header.

Authorization: YOUR_API_KEY

Query Parameters

ParameterTypeRequiredDescription
agent_idstringNoFilter by specific agent
pageintegerNoPage number (default: 1)
limitintegerNoItems per page (default: 20, max: 100)

Example Request

curl -X GET "https://flowgent.ai/api/public/knowledge?page=1&limit=10" \
  -H "Authorization: YOUR_API_KEY"

Response

{
  "knowledge_items": [
    {
      "id": "item-uuid-123",
      "name": "Premium Support Information",
      "created_at": "2023-12-29T10:00:00Z",
      "updated_at": "2023-12-29T10:00:00Z",
      "source": "api",
      "linked_agents": ["agent-uuid-1"]
    }
  ],
  "pagination": {
    "current_page": 1,
    "limit": 10,
    "total_count": 1,
    "total_pages": 1,
    "has_next_page": false,
    "has_previous_page": false
  }
}

Error Responses

// Missing API Key (401)
{
  "error": "API key is required",
  "message": "Please provide an API key in the Authorization header"
}

// Invalid API Key (401)
{
  "error": "Invalid API key",
  "message": "The provided API key is not valid"
}

// Invalid Agent ID (403)
{
  "error": "Access denied",
  "message": "Agent does not belong to your organisation"
}

// Invalid Pagination (400)
{
  "error": "Invalid pagination parameters",
  "message": "Page must be a positive integer and limit must be between 1 and 100"
}

// Internal Server Error (500)
{
  "error": "Internal server error"
}

[GET] Get Knowledge Item

Endpoint

/api/public/knowledge/:id

Description

Retrieve a specific knowledge item by ID.

Authentication

Requires an API key in the Authorization header.

Authorization: YOUR_API_KEY

Path Parameters

ParameterTypeDescription
idstringThe knowledge item's unique identifier

Example Request

curl -X GET "https://flowgent.ai/api/public/knowledge/item-uuid-123" \
  -H "Authorization: YOUR_API_KEY"

Response

{
  "id": "item-uuid-123",
  "name": "Premium Support Information",
  "content": "Our premium support includes 24/7 chat, phone support, and dedicated account management.",
  "created_at": "2023-12-29T10:00:00Z",
  "updated_at": "2023-12-29T10:00:00Z",
  "source": "api",
  "linked_agents": ["agent-uuid-1"]
}

Error Responses

// Missing API Key (401)
{
  "error": "API key is required",
  "message": "Please provide an API key in the Authorization header"
}

// Invalid API Key (401)
{
  "error": "Invalid API key",
  "message": "The provided API key is not valid"
}

// Knowledge Item Not Found (404)
{
  "error": "Knowledge item not found or access denied"
}

// Internal Server Error (500)
{
  "error": "Internal server error"
}

[PATCH] Update Knowledge Item

Endpoint

/api/public/knowledge/:id

Description

Update an existing knowledge item. You can update the name, content, agent links, or description for embedding.

Authentication

Requires an API key in the Authorization header.

Authorization: YOUR_API_KEY

Path Parameters

ParameterTypeDescription
idstringThe knowledge item's unique identifier

Request Body

All fields are optional. Only provide the fields you want to update:

{
  "name": "string",
  "content": "string",
  "agent_ids": ["uuid"] | "uuid",
  "description_to_index_on": "string"
}
ParameterTypeRequiredDescription
namestringNoUpdate the display name
contentstringNoUpdate the content (max 4000 characters, triggers re-embedding)
agent_idsarray | stringNoUpdate agent associations
description_to_index_onstringNoUpdate custom description for embedding

Example Request

curl -X PATCH "https://flowgent.ai/api/public/knowledge/item-uuid-123" \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Updated Premium Support Information",
    "content": "Our premium support now includes 24/7 chat, phone support, dedicated account management, and priority bug fixes.",
    "agent_ids": ["agent-uuid-1", "agent-uuid-2"]
  }'

Response

{
  "id": "item-uuid-123",
  "name": "Updated Premium Support Information",
  "created_at": "2023-12-29T10:00:00Z",
  "updated_at": "2023-12-29T10:00:00Z",
  "source": "api",
  "linked_agents": ["agent-uuid-1", "agent-uuid-2"]
}

Error Responses

// Missing API Key (401)
{
  "error": "API key is required",
  "message": "Please provide an API key in the Authorization header"
}

// Invalid API Key (401)
{
  "error": "Invalid API key",
  "message": "The provided API key is not valid"
}

// Knowledge Item Not Found (404)
{
  "error": "Knowledge item not found or access denied"
}

// Invalid Agent ID (403)
{
  "error": "Access denied",
  "message": "One or more agents do not belong to your organisation"
}

// Content Too Long (400)
{
  "error": "Content exceeds character limit",
  "message": "The content field must be 4000 characters or less."
}

// Invalid JSON Body (400)
{
  "error": "Invalid JSON body",
  "message": "Unexpected token } in JSON at position 123"
}

// Validation Error (400)
{
  "error": "Validation failed",
  "message": "If provided, \"name\" must be a non-empty string."
}

// Internal Server Error (500)
{
  "error": "Internal server error"
}

⚠️ Warning: Overwrite Content

If you update the content of a knowledge item, it will overwrite the existing content. So make sure to include all the content you want to keep.

If you update the content, it will trigger a re-embedding of the knowledge item. If you want to use the description_to_index_on, provide it again.

[DELETE] Delete Knowledge Item

Endpoint

/api/public/knowledge/:id

Description

Permanently delete a knowledge item and all associated data. Only items belonging to your organization can be deleted. This action cannot be undone.

Authentication

Requires an API key in the Authorization header.

Authorization: YOUR_API_KEY

Path Parameters

ParameterTypeDescription
idstringThe knowledge item's unique identifier

Example Request

curl -X DELETE "https://flowgent.ai/api/public/knowledge/item-uuid-123" \
  -H "Authorization: YOUR_API_KEY"

Response

{
  "message": "Knowledge item deleted successfully"
}

Error Responses

// Missing API Key (401)
{
  "error": "API key is required",
  "message": "Please provide an API key in the Authorization header"
}

// Invalid API Key (401)
{
  "error": "Invalid API key",
  "message": "The provided API key is not valid"
}

// Knowledge Item Not Found (404)
{
  "error": "Knowledge item not found or access denied"
}

// Internal Server Error (500)
{
  "error": "Internal server error"
}

⚠️ Warning: Permanent Deletion

This action permanently deletes the knowledge item for all connected agents and cannot be undone.