Docs
API Reference
Overview

API Reference

Complete REST API documentation for AgenticAnts platform.

Base URL

https://api.agenticants.ai/v1

Authentication

All API requests require authentication via API key:

curl https://api.agenticants.ai/v1/traces \
  -H "Authorization: Bearer ants_sk_your_api_key_here"

Rate Limits

PlanRate LimitBurst
Pro1,000 req/min100
EnterpriseCustomCustom

Rate limit headers:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 950
X-RateLimit-Reset: 1635724800

Common Headers

Request Headers

Authorization: Bearer <api_key>
Content-Type: application/json
X-Request-ID: <unique_id>

Response Headers

Content-Type: application/json
X-Request-ID: <unique_id>
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 950

Endpoints

Traces

Create Trace

POST /v1/traces

Request:

{
  "name": "customer-support-query",
  "input": "Help with my order",
  "metadata": {
    "userId": "user_123",
    "sessionId": "session_abc"
  },
  "tags": {
    "environment": "production",
    "team": "support"
  }
}

Response:

{
  "id": "trace_abc123",
  "name": "customer-support-query",
  "startTime": "2025-10-23T14:23:45Z",
  "status": "in_progress",
  "input": "Help with my order",
  "metadata": {...},
  "tags": {...}
}

Get Trace

GET /v1/traces/{trace_id}

Response:

{
  "id": "trace_abc123",
  "name": "customer-support-query",
  "startTime": "2025-10-23T14:23:45Z",
  "endTime": "2025-10-23T14:23:48Z",
  "duration": 2500,
  "status": "completed",
  "input": "Help with my order",
  "output": "I can help you track your order...",
  "spans": [...],
  "tokens": 350,
  "cost": 0.0105,
  "metadata": {...}
}

List Traces

GET /v1/traces?limit=100&offset=0&status=completed

Query Parameters:

  • limit - Number of results (default: 100, max: 1000)
  • offset - Pagination offset
  • status - Filter by status: in_progress, completed, error
  • agent - Filter by agent name
  • startDate - ISO 8601 date
  • endDate - ISO 8601 date

Response:

{
  "data": [
    {...},
    {...}
  ],
  "pagination": {
    "total": 1234,
    "limit": 100,
    "offset": 0,
    "hasMore": true
  }
}

Update Trace

PATCH /v1/traces/{trace_id}

Request:

{
  "output": "I can help you track your order...",
  "status": "completed",
  "metadata": {
    "success": true
  }
}

Spans

Create Span

POST /v1/traces/{trace_id}/spans

Request:

{
  "name": "llm-inference",
  "parentId": null,
  "startTime": "2025-10-23T14:23:46Z",
  "attributes": {
    "model": "gpt-4",
    "temperature": 0.7
  }
}

End Span

PATCH /v1/spans/{span_id}

Request:

{
  "endTime": "2025-10-23T14:23:48Z",
  "status": "ok",
  "output": {...}
}

Metrics

Query Metrics

POST /v1/metrics/query

Request:

{
  "metric": "latency_p95",
  "agent": "customer-support",
  "startDate": "2025-10-01T00:00:00Z",
  "endDate": "2025-10-31T23:59:59Z",
  "granularity": "1h"
}

Response:

{
  "metric": "latency_p95",
  "data": [
    {"timestamp": "2025-10-01T00:00:00Z", "value": 1850},
    {"timestamp": "2025-10-01T01:00:00Z", "value": 1920},
    ...
  ]
}

Available Metrics

MetricDescriptionUnit
latency_p5050th percentile latencyms
latency_p9595th percentile latencyms
latency_p9999th percentile latencyms
throughputRequests per secondreq/s
error_rateError percentage%
token_countTotal tokens usedtokens
costTotal costUSD

Agents

List Agents

GET /v1/agents

Response:

{
  "data": [
    {
      "id": "agent_123",
      "name": "customer-support",
      "version": "1.2.3",
      "framework": "langchain",
      "model": "gpt-4",
      "status": "active",
      "createdAt": "2025-10-01T00:00:00Z"
    }
  ]
}

Get Agent Metrics

GET /v1/agents/{agent_id}/metrics

Response:

{
  "agent": "customer-support",
  "period": "last_24h",
  "metrics": {
    "totalRequests": 1234,
    "avgLatency": 1850,
    "errorRate": 0.5,
    "totalCost": 45.67
  }
}

Webhooks

Create Webhook

POST /v1/webhooks

Request:

{
  "url": "https://your-app.com/webhooks/agenticants",
  "events": ["trace.completed", "alert.triggered"],
  "secret": "whsec_your_webhook_secret"
}

Webhook Events

EventDescription
trace.completedTrace finished
trace.errorTrace had error
alert.triggeredAlert condition met
budget.exceededBudget threshold exceeded
pii.detectedPII found in data

Webhook Payload:

{
  "event": "trace.completed",
  "timestamp": "2025-10-23T14:23:48Z",
  "data": {
    "traceId": "trace_abc123",
    "agent": "customer-support",
    "duration": 2500,
    "status": "completed"
  }
}

Error Handling

Error Response Format

{
  "error": {
    "code": "invalid_request",
    "message": "Missing required field: name",
    "details": {
      "field": "name",
      "reason": "required"
    }
  }
}

Error Codes

CodeHTTP StatusDescription
invalid_request400Invalid request body
authentication_failed401Invalid API key
permission_denied403Insufficient permissions
not_found404Resource not found
rate_limit_exceeded429Too many requests
internal_error500Server error

SDKs

JavaScript/TypeScript

npm install @agenticants/sdk
import { AgenticAnts } from '@agenticants/sdk'
 
const ants = new AgenticAnts({ 
  apiKey: process.env.AGENTICANTS_API_KEY 
})

Python

pip install agenticants
from agenticants import AgenticAnts
 
ants = AgenticAnts(api_key=os.getenv('AGENTICANTS_API_KEY'))

Code Examples

Complete Trace Example

# 1. Create trace
curl -X POST https://api.agenticants.ai/v1/traces \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "customer-support",
    "input": "Help with order"
  }'
 
# Response: {"id": "trace_123", ...}
 
# 2. Create span
curl -X POST https://api.agenticants.ai/v1/traces/trace_123/spans \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "name": "llm-call",
    "startTime": "2025-10-23T14:23:45Z"
  }'
 
# Response: {"id": "span_456", ...}
 
# 3. End span
curl -X PATCH https://api.agenticants.ai/v1/spans/span_456 \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "endTime": "2025-10-23T14:23:47Z",
    "status": "ok"
  }'
 
# 4. Complete trace
curl -X PATCH https://api.agenticants.ai/v1/traces/trace_123 \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "output": "Your order is on the way!",
    "status": "completed"
  }'

Versioning

API version is specified in the URL: /v1/

  • Current version: v1
  • Stable: Yes
  • Deprecation notice: 6 months minimum

Support

Next Steps