Basic Usage Examples

Simple Text Generation

curl -X POST "https://api.agentbase.sh" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{"message": "Write a Python function to calculate fibonacci numbers"}'

Code Generation

curl -X POST "https://api.agentbase.sh" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{"message": "Create a JSON schema for a user profile with name, email, and preferences"}'

Web Search and Research

curl -X POST "https://api.agentbase.sh" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{"message": "Search for the latest developments in AI and summarize the key findings"}'

Complex Automation

curl -X POST "https://api.agentbase.sh" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{"message": "Plan a project roadmap for building a mobile app with user authentication, including technical requirements and timeline"}'

Agent Modes

Fast Mode (Balanced Performance)

curl -X POST "https://api.agentbase.sh" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "message": "Generate code examples",
    "mode": "fast"
  }'

Flash Mode (See Agent Thinking)

curl -X POST "https://api.agentbase.sh" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "message": "Plan a marketing strategy",
    "mode": "flash"
  }'

Max Mode (Complex Reasoning)

curl -X POST "https://api.agentbase.sh" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "message": "Design a complete system architecture",
    "mode": "max"
  }'

Streaming Control

Non-Streaming (Complete Blocks)

curl -X POST "https://api.agentbase.sh" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "message": "Write a product description",
    "streaming": false
  }'

Streaming Enabled (Token-by-Token)

curl -X POST "https://api.agentbase.sh" \
  -H "Content-Type: application/json" \
  -H "Accept: text/event-stream" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "message": "Analyze this website and suggest improvements", 
    "streaming": true
  }'

Session Management

Continue Conversations

# First message - creates a new session
curl -X POST "https://api.agentbase.sh" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{"message": "Help me plan a marketing campaign for a SaaS product"}'

# Save the session ID from the response, then continue the conversation
curl -X POST "https://api.agentbase.sh?session=SESSION_ID" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{"message": "Now create social media content for this campaign"}'
Session Management:
  • Auto-Creation: If you don’t specify a session ID, a new one is automatically created
  • Continue Conversations: Append ?session=[SESSION_ID] to the URL for follow-up messages
  • Persistent Context: The agent remembers previous messages within the same session

Advanced Features

Custom Tools and Rules

curl -X POST "https://api.agentbase.sh" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "message": "Optimize this SQL query for better performance",
    "mode": "max",
    "system": "You are a database optimization expert",
    "rules": ["Always explain your reasoning", "Provide before/after comparisons"],
    "mcpServers": [
      {
        "serverName": "database-tools", 
        "serverUrl": "https://your-mcp-server.com/mcp"
      }
    ]
  }'

Built-in Capabilities

File Processing

curl -X POST "https://api.agentbase.sh" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"message": "Analyze this spreadsheet and create visualizations of the key trends"}'

Web Automation

curl -X POST "https://api.agentbase.sh" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"message": "Monitor competitor pricing on their website and compile a comparison report"}'

Multi-step Planning

curl -X POST "https://api.agentbase.sh" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"message": "Create a complete deployment strategy for a new microservice, including CI/CD pipeline, monitoring, and rollback procedures"}'

Programming Language Integration

JavaScript/Node.js with Error Handling

async function callAgent(message) {
  try {
    const response = await fetch('https://api.agentbase.sh', {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        message: message,
        mode: 'fast'
      })
    });
    
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    
    const data = await response.json();
    return data;
  } catch (error) {
    console.error('Agent request failed:', error);
    throw error;
  }
}

Python with Session Management

import requests

class AgentbaseClient:
    def __init__(self, api_key):
        self.api_key = api_key
        self.session_id = None
        self.base_url = 'https://api.agentbase.sh'
    
    def send_message(self, message, mode='fast'):
        url = self.base_url
        if self.session_id:
            url += f'?session={self.session_id}'
        
        response = requests.post(
            url,
            headers={
                'Authorization': f'Bearer {self.api_key}',
                'Content-Type': 'application/json'
            },
            json={
                'message': message,
                'mode': mode
            }
        )
        
        data = response.json()
        
        # Save session ID for future requests
        if 'session' in data:
            self.session_id = data['session']
        
        return data

# Usage
client = AgentbaseClient('YOUR_API_KEY')
response1 = client.send_message('Plan a marketing campaign')
response2 = client.send_message('Create social media content for this campaign')

Troubleshooting

Common Issues and Solutions

Streaming Problems

# If your stream is choppy, disable streaming for complete blocks
curl -X POST "https://api.agentbase.sh" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "message": "Write documentation",
    "streaming": false
  }'

See Agent Reasoning

# Use flash mode to see the agent's thinking process
curl -X POST "https://api.agentbase.sh" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "message": "Solve this complex problem step by step",
    "mode": "flash"
  }'

Example Streaming Response

data: {"type":"agent_started","session":"[SESSION_ID]"}
data: {"type":"agent_thinking_start","session":"[SESSION_ID]"}
data: {"type":"agent_thinking","session":"[SESSION_ID]","content":"The user is asking me to introduce myself."}
data: {"type":"agent_response_start","session":"[SESSION_ID]"}
data: {"type":"agent_response","session":"[SESSION_ID]","content":"Hello! I'm agentbase, a general-purpose AI agent designed to help you…"}
data: {"type":"agent_tool_use_start","session":"[SESSION_ID]"}
data: {"type":"agent_tool_use","session":"[SESSION_ID]","content":"{\"tool\":\"computer\",\"input\":\"\"}"}
data: {"type":"agent_tool_response","session":"[SESSION_ID]","content":"{\"tool\":\"computer\",\"content\":\"success\"}"}
data: {"type":"agent_step","session":"[SESSION_ID]","step":"1"}
data: {"type":"agent_cost","session":"[SESSION_ID]","cost":"0.0934"}
data: {"type":"agent_completed","session":"[SESSION_ID]"}
For an explanation of every type value, see Streaming Message Types.