JavaScript / TypeScript SDK
Use the AI Teammate API directly with fetch — no SDK package required.
Base URL: https://ai-teammate.net/api · Auth: Bearer <token> or Bearer at_...
Authentication
Login or use an API key to authenticate requests.
JavaScript
// Login & get token
const res = await fetch('https://ai-teammate.net/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email: 'you@example.com',
password: 'your-password',
}),
});
const { access_token } = await res.json();
// Or use an API key directly:
const API_KEY = 'at_your_api_key_here';Agents
List and manage your AI agents.
JavaScript
// List your agents
const res = await fetch('https://ai-teammate.net/api/agents', {
headers: { Authorization: `Bearer ${API_KEY}` },
});
const agents = await res.json();
console.log(agents.map(a => a.name));
// Get a single agent
const agent = await fetch('https://ai-teammate.net/api/agents/${agentId}', {
headers: { Authorization: `Bearer ${API_KEY}` },
}).then(r => r.json());Chat (Streaming)
Send messages and receive streaming responses via SSE.
JavaScript
// Chat with an agent (streaming SSE)
const agentId = 'your-agent-id';
const conversationId = 'conv-123'; // or create one first
const res = await fetch('https://ai-teammate.net/api/agents/${agentId}/chat/stream', {
method: 'POST',
headers: {
Authorization: `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: 'Hello!',
conversation_id: conversationId,
}),
});
// Read SSE stream
const reader = res.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
for (const line of chunk.split('\n')) {
if (line.startsWith('data: ')) {
const data = JSON.parse(line.slice(6));
if (data.type === 'token') {
process.stdout.write(data.content);
}
}
}
}Webhooks
Create webhooks for external integrations. No auth needed for the public endpoint.
JavaScript
// Create a webhook for your agent
const webhook = await fetch('https://ai-teammate.net/api/agents/${agentId}/webhooks', {
method: 'POST',
headers: {
Authorization: `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'My Webhook',
system_prompt_override: 'You are a helpful assistant.',
}),
}).then(r => r.json());
console.log('Webhook URL:', `https://ai-teammate.net/api/webhook/${webhook.token}`);
// Send a message via webhook (no auth required)
const reply = await fetch(`https://ai-teammate.net/api/webhook/${webhook.token}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: 'What is the weather?' }),
}).then(r => r.json());
console.log('Reply:', reply.response);Data Storage
Store and retrieve JSON data scoped to agents or users.
JavaScript
// Store data for an agent
await fetch('https://ai-teammate.net/api/data/agent/${agentId}', {
method: 'POST',
headers: {
Authorization: `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
key: 'user_preferences',
data: { theme: 'dark', language: 'en' },
}),
});
// Retrieve data
const data = await fetch(
'https://ai-teammate.net/api/data/agent/${agentId}?key=user_preferences',
{ headers: { Authorization: `Bearer ${API_KEY}` } }
).then(r => r.json());TypeScript Types
Type definitions for API responses.
TypeScript
// TypeScript type definitions
interface Agent {
id: string;
name: string;
description: string;
system_prompt: string;
model: string;
enabled_skills: string[];
capabilities: string[];
created_at: string;
}
interface ChatStreamEvent {
type: 'meta' | 'token' | 'tool_call' | 'tool_result' | 'done' | 'error';
content?: string;
conversation_id?: string;
run_id?: string;
tool_name?: string;
tool_input?: Record<string, unknown>;
tool_result?: Record<string, unknown>;
usage?: { input_tokens: number; output_tokens: number; credits_used: number };
}
interface WebhookResponse {
response: string;
conversation_id: string;
credits_used: number;
}
interface CreditBalance {
balance: number;
daily_free_balance: number;
plan: 'free' | 'basic' | 'pro' | 'enterprise';
}Rate Limits
- • API: 60 requests/minute per user
- • Webhooks: 10 requests/minute per webhook
- • Chat streaming: 1 concurrent stream per agent
Error Handling
• 401 — Invalid or expired token
• 403 — Insufficient permissions (check API key scope)
• 429 — Rate limit exceeded
• 500 — Server error (retry with backoff)