This API uses Privy for user authentication and wallet management. All protected endpoints require a valid Privy authentication token.
- Frontend Integration: Users authenticate through Privy on your frontend (wallet connection or email signin)
- Token Generation: Privy generates an authentication token
- API Requests: Include the token in the
Authorizationheader for protected endpoints
Authorization: Bearer <privy_token>
Content-Type: application/jsonauthenticatePrivy: Verifies Privy token and setsreq.userwith user dataauthenticateAndSync: Verifies token + automatically syncs user data to database
After authentication, req.user contains:
{
id: string; // User UUID in your database
privyId: string; // Privy user ID
email?: string; // User's email (if available)
walletAddress?: string; // Primary wallet address
linkedAccounts?: any[]; // Array of linked accounts from Privy
createdAt?: Date; // Account creation timestamp
updatedAt?: Date; // Last update timestamp
}401 Unauthorized:
{
"success": false,
"message": "Missing or invalid authorization header",
"error": "Authentication failed"
}403 Forbidden:
{
"success": false,
"message": "Invalid or expired token",
"error": "Authentication failed"
}-
Description: Health check endpoint.
-
Authentication: None required
-
Response:
{ "status": "Limitless", "timestamp": "2025-08-02T12:34:56.789Z", "method": "GET", "path": "/service/health" }
This API provides comprehensive functionality for:
- User Management: Privy integration for user authentication and wallet management
- Chat Management: Create and manage user conversations
- Message Management: Handle chat messages with role-based messaging
-
Description: Sync user with Privy authentication system.
-
Authentication: None required (public endpoint for initial user setup)
-
Request:
{ "privyId": "string (required, min 1 char)", "email": "string (optional, must be valid email format)", "walletAddress": "string (optional)", "linkedAccounts": "array (optional, any[])", "createdAt": "string (optional, ISO date string)" } -
Response (200 OK):
{ "success": true, "user": { "id": "b1a2c3d4-e5f6-7890-1234-56789abcdef0", "privyId": "privy_123456", "email": "user@example.com", "walletAddress": "0x1234567890abcdef1234567890abcdef12345678", "linkedAccounts": [], "createdAt": "2025-08-02T12:00:00.000Z", "updatedAt": "2025-08-02T12:00:00.000Z" } } -
Error Responses:
// 400 Bad Request { "success": false, "message": "Validation error", "data": "Privy ID is required" } // 500 Internal Server Error { "success": false, "message": "Failed to sync user", "data": "error details" }
-
Description: Get user by Privy ID.
-
Authentication: Required (
authenticatePrivy) -
Params:
privyId(string, required, min 1 char) -
Response (200 OK):
{ "success": true, "message": "User retrieved successfully", "data": { "id": "b1a2c3d4-e5f6-7890-1234-56789abcdef0", "privyId": "privy_123456", "email": "user@example.com", "walletAddress": "0x1234567890abcdef1234567890abcdef12345678", "linkedAccounts": [], "createdAt": "2025-08-02T12:00:00.000Z", "updatedAt": "2025-08-02T12:00:00.000Z" } } -
Error Responses:
// 401 Unauthorized { "success": false, "data": { "message": "Missing or invalid authorization header" } } // 404 Not Found { "success": false, "data": { "message": "User not found" } }
-
Description: Create a new chat for the authenticated user.
-
Authentication: Required (
authenticateAndSync- auto-syncs user data) -
Request:
{ "title": "string (required, min 1 char, max 255 chars)" }Note:
userIdis automatically extracted from the authenticated user token. -
Response (201 Created):
{ "success": true, "message": "Chat created successfully", "data": { "id": "c1a2b3d4-e5f6-7890-1234-56789abcdef1", "title": "DeFi Portfolio Analysis", "userId": "b1a2c3d4-e5f6-7890-1234-56789abcdef0", "createdAt": "2025-08-02T12:00:00.000Z", "updatedAt": "2025-08-02T12:00:00.000Z" } } -
Error Responses:
// 400 Bad Request { "success": false, "message": "Validation error", "data": "Title is required and must be between 1-255 characters" } // 401 Unauthorized { "success": false, "data": { "message": "Missing or invalid authorization header" } }
-
Description: Get a specific chat by ID.
-
Authentication: Required (
authenticatePrivy) -
Params:
id(string, UUID format, required) -
Response (200 OK):
{ "success": true, "message": "Chat retrieved successfully", "data": { "id": "c1a2b3d4-e5f6-7890-1234-56789abcdef1", "title": "DeFi Portfolio Analysis", "userId": "b1a2c3d4-e5f6-7890-1234-56789abcdef0", "createdAt": "2025-08-02T12:00:00.000Z", "updatedAt": "2025-08-02T12:00:00.000Z" } } -
Error Responses:
// 404 Not Found { "success": false, "data": { "message": "Chat not found" } }
-
Description: Get all chats for a specific user.
-
Authentication: Required (
authenticatePrivy) -
Params:
userId(string, UUID format, required) -
Response (200 OK):
{ "success": true, "message": "Chats retrieved successfully", "data": [ { "id": "c1a2b3d4-e5f6-7890-1234-56789abcdef1", "title": "DeFi Portfolio Analysis", "userId": "b1a2c3d4-e5f6-7890-1234-56789abcdef0", "createdAt": "2025-08-02T12:00:00.000Z", "updatedAt": "2025-08-02T12:00:00.000Z" }, { "id": "c2a2b3d4-e5f6-7890-1234-56789abcdef2", "title": "Token Swap Analysis", "userId": "b1a2c3d4-e5f6-7890-1234-56789abcdef0", "createdAt": "2025-08-02T11:00:00.000Z", "updatedAt": "2025-08-02T11:00:00.000Z" } ] }
-
Description: Update an existing chat.
-
Authentication: Required (
authenticatePrivy) -
Params:
id(string, UUID format, required) -
Request:
{ "title": "string (required, min 1 char, max 255 chars)" } -
Response (200 OK):
{ "success": true, "message": "Chat updated successfully", "data": { "id": "c1a2b3d4-e5f6-7890-1234-56789abcdef1", "title": "Updated Chat Title", "userId": "b1a2c3d4-e5f6-7890-1234-56789abcdef0", "createdAt": "2025-08-02T12:00:00.000Z", "updatedAt": "2025-08-02T12:30:00.000Z" } }
-
Description: Delete a chat and all its associated messages.
-
Authentication: Required (
authenticatePrivy) -
Params:
id(string, UUID format, required) -
Response (200 OK):
{ "success": true, "message": "Chat deleted successfully", "data": null }
-
Description: Create a new message with automatic AI response generation.
-
Authentication: Required (
authenticateAndSync- auto-syncs user data) -
Request:
{ "content": "string (required, min 1 char)", "chatId": "string (required, UUID format)", "role": "user|assistant (required, enum: 'user' or 'assistant')" }Note:
userIdis automatically extracted from the authenticated user token.- When
roleis "user", the system automatically generates an AI assistant response using LangChain and OpenAI. - AI responses may include usage of DeFi tools for token prices, swap quotes, gas prices, etc.
-
Response (201 Created):
{ "success": true, "message": "Messages created successfully with AI response", "data": { "userMessage": { "id": "m1a2b3d4-e5f6-7890-1234-56789abcdef0", "content": "What's the current price of ETH?", "role": "user", "chatId": "c1a2b3d4-e5f6-7890-1234-56789abcdef1", "userId": "b1a2c3d4-e5f6-7890-1234-56789abcdef0", "createdAt": "2025-08-02T12:00:00.000Z", "updatedAt": "2025-08-02T12:00:00.000Z" }, "aiMessage": { "id": "m2a2b3d4-e5f6-7890-1234-56789abcdef1", "content": "The current price of ETH is $3,420.50 USD. This price is updated in real-time and reflects the latest market data.", "role": "assistant", "chatId": "c1a2b3d4-e5f6-7890-1234-56789abcdef1", "userId": "b1a2c3d4-e5f6-7890-1234-56789abcdef0", "createdAt": "2025-08-02T12:00:02.000Z", "updatedAt": "2025-08-02T12:00:02.000Z" } } } -
Error Responses:
// 400 Bad Request { "success": false, "message": "Validation error", "data": "Content is required and must be at least 1 character" } // 401 Unauthorized { "success": false, "data": { "message": "Missing or invalid authorization header" } } // 404 Not Found (if chatId doesn't exist) { "success": false, "data": { "message": "Chat not found" } }
-
Description: Get a specific message by ID.
-
Authentication: Required (
authenticatePrivy) -
Params:
id(string, UUID format, required) -
Response (200 OK):
{ "success": true, "message": "Message retrieved successfully", "data": { "id": "m1a2b3d4-e5f6-7890-1234-56789abcdef0", "content": "What's the current price of ETH?", "role": "user", "chatId": "c1a2b3d4-e5f6-7890-1234-56789abcdef1", "userId": "b1a2c3d4-e5f6-7890-1234-56789abcdef0", "createdAt": "2025-08-02T12:00:00.000Z", "updatedAt": "2025-08-02T12:00:00.000Z" } }
-
Description: Get all messages in a specific chat.
-
Authentication: Required (
authenticatePrivy) -
Params:
chatId(string, UUID format, required) -
Response (200 OK):
{ "success": true, "message": "Messages retrieved successfully", "data": [ { "id": "m1a2b3d4-e5f6-7890-1234-56789abcdef0", "content": "What's the current price of ETH?", "role": "user", "chatId": "c1a2b3d4-e5f6-7890-1234-56789abcdef1", "userId": "b1a2c3d4-e5f6-7890-1234-56789abcdef0", "createdAt": "2025-08-02T12:00:00.000Z", "updatedAt": "2025-08-02T12:00:00.000Z" }, { "id": "m2a2b3d4-e5f6-7890-1234-56789abcdef1", "content": "The current price of ETH is $3,420.50 USD.", "role": "assistant", "chatId": "c1a2b3d4-e5f6-7890-1234-56789abcdef1", "userId": "b1a2c3d4-e5f6-7890-1234-56789abcdef0", "createdAt": "2025-08-02T12:00:02.000Z", "updatedAt": "2025-08-02T12:00:02.000Z" } ] }
-
Description: Get all messages by a specific user.
-
Authentication: Required (
authenticatePrivy) -
Params:
userId(string, UUID format, required) -
Response (200 OK):
{ "success": true, "message": "Messages retrieved successfully", "data": [ { "id": "m1a2b3d4-e5f6-7890-1234-56789abcdef0", "content": "What's the current price of ETH?", "role": "user", "chatId": "c1a2b3d4-e5f6-7890-1234-56789abcdef1", "userId": "b1a2c3d4-e5f6-7890-1234-56789abcdef0", "createdAt": "2025-08-02T12:00:00.000Z", "updatedAt": "2025-08-02T12:00:00.000Z" } ] }
-
Description: Update an existing message.
-
Authentication: Required (
authenticatePrivy) -
Params:
id(string, UUID format, required) -
Request:
{ "content": "string (required, min 1 char)" } -
Response (200 OK):
{ "success": true, "message": "Message updated successfully", "data": { "id": "m1a2b3d4-e5f6-7890-1234-56789abcdef0", "content": "Updated message content", "role": "user", "chatId": "c1a2b3d4-e5f6-7890-1234-56789abcdef1", "userId": "b1a2c3d4-e5f6-7890-1234-56789abcdef0", "createdAt": "2025-08-02T12:00:00.000Z", "updatedAt": "2025-08-02T12:30:00.000Z" } }
-
Description: Delete a specific message.
-
Authentication: Required (
authenticatePrivy) -
Params:
id(string, UUID format, required) -
Response (200 OK):
{ "success": true, "message": "Message deleted successfully", "data": null }
-
Description: Test AI functionality without authentication (for development and testing).
-
Authentication: None required (public endpoint)
-
Request:
{ "message": "string (required, min 1 char)", "chatId": "string (optional, UUID format - for continuing conversations)" }Note:
- Creates a test user automatically if not provided
- Supports continuing conversations by providing
chatIdfrom previous responses - Same AI capabilities as authenticated endpoints
- Uses all available DeFi tools and multi-step reasoning
-
Response (200 OK):
{ "success": true, "response": "AI assistant response with potential tool usage results", "chatId": "c1a2b3d4-e5f6-7890-1234-56789abcdef1", "metadata": { "timestamp": "2025-08-02T12:00:00.000Z", "processing_time": "2.45s", "tools_used": ["token_prices", "gas_prices"] } } -
Error Responses:
// 400 Bad Request { "success": false, "message": "Message is required" } // 500 Internal Server Error { "success": false, "message": "AI processing failed", "error": "error details" }
-
Example Usage:
# Basic AI query curl -X POST http://localhost:3000/ai/test \ -H "Content-Type: application/json" \ -d '{ "message": "What is the current price of ETH?" }' # Continue conversation curl -X POST http://localhost:3000/ai/test \ -H "Content-Type: application/json" \ -d '{ "message": "Now get me a swap quote for 1 ETH to USDC", "chatId": "c1a2b3d4-e5f6-7890-1234-56789abcdef1" }' # Complex multi-tool query curl -X POST http://localhost:3000/ai/test -H "Content-Type: application/json" \ -d '{ "message": "Check gas prices on Ethereum, get the current ETH price, and calculate the cost to swap 1 ETH for USDC" }'
The API includes LangChain.js integration with OpenAI for intelligent message responses and DeFi operations.
-
1inch Fusion Swap Tool (
get_swap_quote):- Get real-time swap quotes and rates across multiple blockchains
- Supports: Ethereum, Polygon, BSC, Arbitrum, Optimism, Avalanche, Gnosis, Fantom, and more
- Get best rates for token swaps with slippage protection
- Supports both token symbols (ETH, USDC, BNB) and contract addresses
- Example queries:
- "Get a quote to swap 1 ETH for USDC on Ethereum"
- "How much MATIC would I get for 100 USDC on Polygon?"
- "Compare swap rates for 1 BNB to USDT on BSC"
-
Token Information Tool (
get_token_info):- Get detailed information about any token including address, symbol, name, decimals
- Works across all supported blockchains
- Supports both token symbols and contract addresses
- Example queries:
- "What is the contract address for USDC on Ethereum?"
- "Get information about token 0x..."
- "Show me details for MATIC token"
-
Token Prices Tool (
token_prices):- Real-time Prices: Get current market prices for any token
- Bulk Queries: Get prices for multiple tokens simultaneously
- Supported Currencies: Check available currencies for price data
- Supports: Ethereum, Polygon, BSC, Arbitrum, Optimism, Avalanche, and more
- Currently supports USD pricing
- Example queries:
- "What's the current price of ETH and USDC?"
- "Get prices for BTC, ETH, and MATIC on Polygon"
- "What currencies are supported for price queries on Ethereum?"
-
Gas Prices Tool (
gas_prices):- Real-time Gas Prices: Get current EIP-1559 gas prices with priority levels
- Cost Estimates: Calculate transaction costs for different operation types
- Priority Levels: Low, Medium, High, and Instant priority options
- Multi-chain Support: Ethereum, Polygon, BSC, Arbitrum, Optimism, Avalanche, and more
- Transaction Types: Simple transfers, token transfers, and DeFi operations
- Example queries:
- "What are the current gas prices on Ethereum?"
- "Show me gas prices with cost estimates for Polygon"
- "Get gas prices for Arbitrum with ETH at $3400"
- "What's the cost to do a DeFi transaction on Ethereum right now?"
-
Token Balances Tool (
token_balances):- All Token Balances: Get complete token portfolio for any wallet address
- Custom Token Balances: Check specific token balances for a wallet
- Multiple Wallets Analysis: Compare token holdings across multiple wallets
- Smart Filtering: Automatically filters out zero balances for cleaner results
- Multi-chain Support: Ethereum, Polygon, BSC, Arbitrum, Optimism, Avalanche, and more
- Token Recognition: Automatically identifies common tokens by symbol
- Example queries:
- "Show me all token balances for wallet 0x742d35Cc6634C0532925a3b8D5C9E5E0d96B8C79"
- "Get USDC and USDT balances for wallet 0x... on Ethereum"
- "Compare ETH balances across these wallets: 0x..., 0x..., 0x..."
- "What tokens does this wallet hold on Polygon with non-zero balances?"
-
Transaction History Tool (
transaction_history):- Complete History: Get comprehensive transaction history for any wallet
- Advanced Search: Search with multiple filter options (time, chains, transaction types)
- Swap History: Dedicated swap transaction analysis
- Multi-chain Support: Track transactions across all supported blockchains
- Transaction Details: Includes gas fees, token actions, metadata, and 1inch-specific info
- Smart Formatting: Displays recent events with relevant context and summaries
- Example queries:
- "Show me recent transaction history for wallet 0x742d35Cc6634C0532925a3b8D5C9E5E0d96B8C79"
- "Get all swap transactions on Ethereum for this wallet"
- "Search for transactions involving USDC in the last 30 days"
- "Show me all 1inch Fusion swaps for this address"
- "What transactions happened on Polygon between timestamps X and Y?"
-
NFT Operations Tool (
nft_operations):- Supported Chains: Get list of supported chains for NFT operations
- NFT Collections: Retrieve all NFTs owned by a wallet address
- NFT Details: Get detailed information about specific NFTs
- Supports: Ethereum, Polygon, Arbitrum, Avalanche, Gnosis, Klaytn, Optimism, Base
- Providers: OpenSea, Rarible, POAP
- Example queries:
- "What chains support NFT operations?"
- "Show me all NFTs owned by address 0x742d35Cc6634C0532925a3b8D5C9E5E0d96B8C79"
- "Get details for NFT token ID 1234 on contract 0x... on Ethereum using OpenSea"
OPENAI_API_KEY=your_openai_api_key_here
ONEINCH_API_KEY=your_1inch_api_key_hereGetting API Keys:
- OpenAI: Visit OpenAI Platform
- 1inch: Visit 1inch Developer Portal to get your API key
# DeFi swap quote (using test endpoint)
curl -X POST http://localhost:3000/ai/test \
-H "Content-Type: application/json" \
-d '{
"message": "Get a quote to swap 1 ETH for USDC on Ethereum with 0.5% slippage from wallet 0x742d35Cc6634C0532925a3b8D5C9E5E0d96B8C79"
}'
# Token prices
curl -X POST http://localhost:3000/ai/test \
-H "Content-Type: application/json" \
-d '{
"message": "What are the current prices of ETH, USDC, and BTC on Ethereum?"
}'
# Multiple chain price comparison
curl -X POST http://localhost:3000/ai/test \
-H "Content-Type: application/json" \
-d '{
"message": "Get MATIC price on Polygon and ETH price on Ethereum"
}'
# Supported currencies
curl -X POST http://localhost:3000/ai/test \
-H "Content-Type: application/json" \
-d '{
"message": "What currencies are supported for price queries on Ethereum?"
}'
# Token information
curl -X POST http://localhost:3000/ai/test \
-H "Content-Type: application/json" \
-d '{
"message": "What is the contract address and decimals for USDC on Polygon?"
}'
# Gas prices
curl -X POST http://localhost:3000/ai/test \
-H "Content-Type: application/json" \
-d '{
"message": "What are the current gas prices on Ethereum?"
}'
# Gas prices with cost estimates
curl -X POST http://localhost:3000/ai/test \
-H "Content-Type: application/json" \
-d '{
"message": "Show me gas prices with cost estimates for Polygon assuming ETH is at $3400"
}'
# Multi-chain gas comparison
curl -X POST http://localhost:3000/ai/test \
-H "Content-Type: application/json" \
-d '{
"message": "Compare gas prices between Ethereum and Arbitrum"
}'
# Token balances - all tokens
curl -X POST http://localhost:3000/ai/test \
-H "Content-Type: application/json" \
-d '{
"message": "Show me all token balances for wallet 0x742d35Cc6634C0532925a3b8D5C9E5E0d96B8C79 on Ethereum"
}'
# Token balances - specific tokens
curl -X POST http://localhost:3000/ai/test \
-H "Content-Type: application/json" \
-d '{
"message": "Get USDC and USDT balances for wallet 0x742d35Cc6634C0532925a3b8D5C9E5E0d96B8C79"
}'
# Token balances - multiple wallets
curl -X POST http://localhost:3000/ai/test \
-H "Content-Type: application/json" \
-d '{
"message": "Compare USDC balances for these wallets: 0x742d35Cc6634C0532925a3b8D5C9E5E0d96B8C79, 0x8ba1f109551bD432803012645Hac136c"
}'
# Transaction history - recent events
curl -X POST http://localhost:3000/ai/test \
-H "Content-Type: application/json" \
-d '{
"message": "Show me recent transaction history for wallet 0x742d35Cc6634C0532925a3b8D5C9E5E0d96B8C79"
}'
# Transaction history - swap events only
curl -X POST http://localhost:3000/ai/test \
-H "Content-Type: application/json" \
-d '{
"message": "Get all swap transactions on Ethereum for wallet 0x742d35Cc6634C0532925a3b8D5C9E5E0d96B8C79"
}'
# Transaction history - filtered search
curl -X POST http://localhost:3000/ai/test \
-H "Content-Type: application/json" \
-d '{
"message": "Search for USDC transactions on Ethereum for wallet 0x742d35Cc6634C0532925a3b8D5C9E5E0d96B8C79 in the last 7 days"
}'
# NFT operations
curl -X POST http://localhost:3000/ai/test \
-H "Content-Type: application/json" \
-d '{
"message": "Show me all NFTs owned by 0x742d35Cc6634C0532925a3b8D5C9E5E0d96B8C79 on Ethereum"
}'
# Using authenticated endpoints
curl -X POST http://localhost:3000/user/messages \
-H "Authorization: Bearer <your_privy_token>" \
-H "Content-Type: application/json" \
-d '{
"content": "Get current prices for ETH and USDC, then show me swap rate between them",
"chatId": "chat-uuid",
"role": "user"
}'
# Complex multi-step query with authenticated endpoint
curl -X POST http://localhost:3000/user/messages \
-H "Authorization: Bearer <your_privy_token>" \
-H "Content-Type: application/json" \
-d '{
"content": "Check my USDC balance, get current gas prices, then calculate the best swap rate for 100 USDC to DAI",
"chatId": "chat-uuid",
"role": "user"
}'All API responses follow a consistent format using the standardized response helpers:
{
"success": true,
"message": "Operation completed successfully",
"data": {
/* response data */
}
}{
"success": false,
"message": "Error description",
"data": "Additional error details or validation messages"
}- 200 OK: Successful GET, PUT, DELETE operations
- 201 Created: Successful POST operations (resource creation)
- 400 Bad Request: Validation errors, malformed requests
- 401 Unauthorized: Missing or invalid authentication
- 404 Not Found: Resource not found
- 500 Internal Server Error: Server-side processing errors