Preview Version
🚧 This is documentation for a preview version of the service. It's only meant for running as playground before the 1st major release. Expect much better experience when we go live!
Using Crowdnet for AI Token Generation
This guide explains how to use Crowdnet's distributed network for large-scale AI token generation at $0.30 per million tokens.
🚀 Getting Started
- Sign up at platform.crowdnet.ai
- Complete the Consumer onboarding:
- Select your monthly token allocation
- Choose your target AI markets
- Generate your API key from the dashboard
API Authentication
All requests require authentication using API keys. Include these headers in all requests:
const headers = {
"X-API-Key": "your_api_key_here",
"X-User-Email": "your_registered_email",
"Content-Type": "application/json",
};
API Endpoints
1. Generate Text
// Using Server-Sent Events (SSE)
const generateText = async (prompt, conversationId = null) => {
const eventSource = new EventSource("/generate", {
headers: {
"X-API-Key": "your_api_key_here",
"X-User-Email": "your_registered_email",
},
});
eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log(data.response);
// Handle end of stream
if (data.response === "[END]") {
eventSource.close();
}
};
eventSource.onerror = (error) => {
console.error("Error:", error);
eventSource.close();
};
};
// Using the CrowdNet client
const client = new CrowdNetClient({ headers });
const response = await client.completions.create({
prompt: "Your text prompt here",
conversation_id: "optional-conversation-id", // For related prompts
model: "best-available",
stream: true,
callbacks: {
onToken: (token) => console.log("New token:", token),
onComplete: (response) => console.log("Complete:", response),
onError: (error) => console.error("Error:", error),
},
});
2. Health Check
Simple endpoint to verify service availability:
const checkHealth = async () => {
const response = await fetch("/", {
headers: headers,
});
if (response.ok) {
console.log("Service is healthy");
}
};
Error Handling
Handle various API response codes:
try {
const response = await client.completions.create({
prompt: "Your prompt",
});
} catch (error) {
switch (error.status) {
case 400:
console.error("Bad Request - Missing or invalid parameters");
break;
case 401:
console.error("Unauthorized - Invalid or missing API key/email");
break;
case 403:
console.error("Forbidden - Monthly token limit exceeded");
break;
case 500:
console.error("Internal Server Error");
break;
case 503:
console.error("Service Unavailable - No available swarm members");
break;
default:
console.error("Unknown error:", error);
}
}
Best Practices
-
Conversation Management:
- Reuse conversation IDs for related prompts
- This helps maintain context and improve response quality
-
Error Handling:
- Implement proper error handling for all API calls
- Consider implementing retry logic for 503 errors
- Monitor token limits to avoid service interruption
-
Performance Optimization:
- Use streaming for long responses
- Monitor GPU tiers for optimal performance
- Handle stale connections appropriately
-
Security:
- Never expose your API key in client-side code
- Implement proper key rotation practices
- Monitor usage patterns for anomalies
⚠️ Important Considerations
When using Crowdnet's distributed network:
-
Token usage:
- Token usage is calculated based on response length
-
Network Status:
- Service availability depends on active swarm members
- System automatically handles stale connections
-
Performance:
- Response time varies based on available members
- Network stability affects generation reliability
-
Support:
- Contact support for implementation assistance
- Monitor the status endpoint for network health
- Check documentation for updates and best practices