The GET /content/:id endpoint allows you to check the status of a previously submitted content request and retrieve the results when processing is complete. This endpoint is used for polling the status of your request until it's ready.
https://www.trendifi.app/api/v1/content/:id
Parameter | Type | Description |
---|---|---|
id | string | The unique identifier of the content request (returned from POST /content) |
Header | Required | Description |
---|---|---|
Authorization | Yes | Your TrendiFi API key as a Bearer token (e.g., 'Bearer YOUR_API_KEY') |
The response from the GET /content/:id endpoint will vary depending on the current status of the content request. There are three possible status values: "processing", "completed", and "failed".
When the content is still being processed, the response will include the status:
{
"id": "ins_01H9XK7ABCDEFGHIJKLMNOPQRS",
"status": "processing",
"created_at": "2023-09-15T14:23:45Z"
}
When the content processing is complete, the response will include the full content data:
{
"id": "ins_01H9XK7ABCDEFGHIJKLMNOPQRS",
"status": "completed",
"created_at": "2023-09-15T14:23:45Z",
"completed_at": "2023-09-15T14:24:15Z",
"result": {
"topic": "AI trends in healthcare",
"insight": "AI is transforming healthcare through several key trends...
... (450 words, truncated)"
}
}
When polling for the status of a content request, follow these best practices to ensure efficient usage of the API:
Here are examples of how to implement polling with exponential backoff in different programming languages:
// Node.js polling example
async function pollContent(contentId) {
const apiKey = 'YOUR_API_KEY';
const apiUrl = 'https://trendifi.app/api/v1';
let delay = 3000; // Start with 3 second delay to avoid rate limiting
while (true) {
try {
const response = await fetch(apiUrl + '/content/' + contentId, {
headers: {
'Authorization': 'Bearer ' + apiKey
}
});
if (!response.ok) {
throw new Error('HTTP error! status: ' + response.status);
}
const data = await response.json();
if (data.status === 'completed') {
console.log('Content is ready!');
return data.result;
} else if (data.status === 'failed') {
throw new Error('Content processing failed: ' + data.error.message);
}
// Still processing, wait and try again
console.log('Content still processing...');
delay = Math.min(delay * 1.5, 30000); // Max delay of 30 seconds
await new Promise(resolve => setTimeout(resolve, delay));
} catch (error) {
console.error('Error polling content:', error);
throw error;
}
}
}
When errors occur during API calls, TrendiFi returns standard HTTP status codes along with detailed error information. For most error cases, you'll receive a structured error response with an error code that helps identify the specific issue.
TrendiFi's API uses standard HTTP status codes to indicate the success or failure of requests. Note: When errors occur, tokens are not deducted from your account.
⚠️ Important:
When handling errors, always check the HTTP status code first, then examine the JSON error object. This is especially critical for 400-404 status codes, as they provide specific information about what went wrong.
Status Code | Description |
---|---|
200 OK | The request was successful |
400 Bad Request | The request was invalid or missing required parameters |
401 Unauthorized | Invalid or missing API key |
402 Payment Required | Account has insufficient tokens (0 tokens in balance) |
404 Not Found | The requested resource does not exist |
405 Method Not Allowed | The HTTP method used is not supported for this endpoint (e.g., using GET instead of POST) |
429 Too Many Requests | Rate limit exceeded |
500 Internal Server Error | An error occurred on the server |
Error responses include a JSON body with an error
object containing a message and an error code:
{ "error": { "message": "No topic provided", "error_code": "missing_topic" } }
When a requested resource is not found, you'll receive a 404 status code with a specific error message:
{ "error": { "code": "not_found", "message": "Insight with ID 'ins_01H9XK7ABCDEFGHIJKLMNOPQRS' not found" } }
The following table lists all possible error codes that may be returned by the TrendiFi API. Important: When errors occur, tokens are not deducted from your account.
Error Code | Description | HTTP Status |
---|---|---|
missing_topic | No topic was provided in the request | 400 |
missing_data_structure | No data structure was provided for a custom_json format request | 400 |
invalid_data_structure | The data structure provided is invalid or malformed | 400 |
unauthorized | Invalid or missing API key | 401 |
insufficient_tokens | The account does not have enough tokens to process the request | 402 |
not_found | The specified resource (content/insight) ID does not exist | 404 |
content_not_found | The specified content ID does not exist (legacy code) | 404 |
endpoint_not_found | The requested API endpoint does not exist | 404 |
incorrect_method | The HTTP method used is not supported for this endpoint | 405 |
rate_limit_exceeded | The API rate limit has been exceeded | 429 |
internal_server_error | An unexpected error occurred on the server | 500 |