API Reference
Complete API documentation for integrating with the Portal platform.
Authentication
All API requests require authentication using a Bearer token in the Authorization header.
Authorization: Bearer YOUR_API_KEY
Base URL
https://api.portal.example.com/v1
Endpoints
Chat Completion
Create a chat completion with a specified model.
Endpoint: POST /chat/completions
Request Body:
{
"model": "gpt-4",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the capital of France?"
}
],
"temperature": 0.7,
"max_tokens": 150
}
Response:
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-4",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The capital of France is Paris."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 8,
"total_tokens": 28
}
}
File Upload
Upload files to S3 storage.
Endpoint: POST /upload
Request: Multipart form data with file
curl -X POST https://api.portal.example.com/v1/upload \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@/path/to/file.pdf"
Response:
{
"code": 0,
"msg": "success",
"data": {
"key": "uploads/user_123/1699564800_document.pdf",
"url": "https://bucket.s3.amazonaws.com/uploads/user_123/1699564800_document.pdf",
"filename": "document.pdf",
"size": 1024000
}
}
Rate Limits
- Free tier: 100 requests per hour
- Pro tier: 1,000 requests per hour
- Enterprise: Custom limits
Error Codes
| Code | Description |
|---|---|
| 400 | Bad Request - Invalid parameters |
| 401 | Unauthorized - Invalid API key |
| 403 | Forbidden - Insufficient permissions |
| 429 | Too Many Requests - Rate limit exceeded |
| 500 | Internal Server Error |
SDKs
We provide official SDKs for popular languages: