REST API Overview

Programmatic access to agents, data sources, and analytics.

Base URL

https://api.twig.so

Protocol: HTTPS only (HTTP redirects to HTTPS with 301)

API versioning: Path-based (/api/v1/... for new endpoints, /api/... for legacy)

Authentication

All API requests require authentication using an API key:

curl -X GET https://api.twig.so/api/agents \
  -H "Authorization: Bearer YOUR_API_KEY"

See Authentication for details on generating API keys.

Rate Limits

API requests are rate-limited per organization:

Plan
Requests per Minute
Requests per Day

Free

20

1,000

Pro

100

10,000

Enterprise

1,000+

Custom

Rate limit headers are included in every response:

When exceeded, you'll receive a 429 Too Many Requests response.

Response Format

Success Response

Error Response

Common Error Codes

Code
Status
Description

invalid_request

400

Malformed request

unauthorized

401

Invalid or missing API key

forbidden

403

Insufficient permissions

not_found

404

Resource not found

rate_limit_exceeded

429

Too many requests

internal_error

500

Server error

Core Endpoints

Chat & Completion

POST /api/chat

Generate an AI response for a given prompt.

Response:

Agents

GET /api/ai-agent-managers

List all AI agents in your organization.

POST /api/ai-agent-managers

Create a new AI agent.

GET /api/ai-agent-managers/:id

Get details of a specific agent.

PUT /api/ai-agent-managers/:id

Update an agent's configuration.

DELETE /api/ai-agent-managers/:id

Delete an agent.

Data Sources

GET /api/data-specs

List all data sources.

POST /api/data-specs

Create a new data source.

POST /api/data-specs/:id/process

Trigger processing/sync for a data source.

Interactions

GET /api/interactions

List recent interactions.

POST /api/interactions/feedback

Submit feedback on an interaction.

Analytics

GET /api/analytics/charts/dashboard

Get analytics dashboard data.

Advanced Features

Streaming Responses

Enable streaming for real-time response delivery:

Responses are sent as Server-Sent Events (SSE):

Semantic Search Only

Retrieve relevant documents without generating a response:

Webhooks

Register webhooks to receive events:

SDKs & Client Libraries

JavaScript/TypeScript

Python (Coming Soon)

Best Practices

1. Error Handling

Always handle errors gracefully:

2. Rate Limit Management

Implement exponential backoff:

3. Caching

Cache responses for frequently asked questions:

4. Session Management

Maintain conversation context with session IDs:

Next Steps

Last updated