POST /content

This endpoint allows you to request a new content on any topic. The request is processed asynchronously, and you'll receive a request ID that you can use to check the status and retrieve the results.

Endpoint

POST https://www.trendifi.app/api/v1/content

Request Parameters

ParameterTypeRequiredDescription
topicstringYesThe topic or question to analyze
data_structureobjectYesCustom data structure for predicted content

Parameter Details

topic

The topic parameter should be a specific question or topic you want to analyze. It can be a broad topic like "AI trends in healthcare" or a specific question like "What are the latest developments in quantum computing?". The more specific your topic, the more focused the content will be.

data_structure

The data_structure parameter defines the structure of the custom JSON response, allowing you to get results in exactly the format your application needs. It should be a JSON object that defines the structure you want, with field names as keys and field types and descriptions as values.

Supported types are:

  • "string" - Text fields
  • "number" - Numeric values
  • "boolean" - True/false values
  • [] - Arrays (e.g., ["string"] for an array of strings)
  • {} - Nested objects

The TrendiFi API requires a data_structure parameter that defines exactly how you want your content data to be organized. This allows you to get data in a format that perfectly matches your application's needs:

// POST https://trendifi.app/api/v1/content
        {
          "topic": "Electric vehicles market trends",
          "data_structure": {
            "summary": "string - concise overview of current EV market trends in 2-3 sentences",
            "key_trends": [{
              "name": "string - short name of a specific market trend",
              "description": "string - detailed explanation with supporting data points",
              "impact_score": "number - rating from 1-10 of market impact"
            }],
            "market_leaders": ["string - names of top companies with brief description of their market position"],
            "regional_insights": {
              "north_america": "string - key developments and adoption rates in North American markets",
              "europe": "string - regulatory environment and market growth in European countries",
              "asia": "string - manufacturing trends and consumer adoption in Asian markets"
            },
            "forecast": {
              "growth_rate": "number - projected annual growth percentage for next 3 years",
              "challenges": ["string - specific obstacles facing the industry with potential solutions"],
              "opportunities": ["string - emerging areas for innovation and investment"] 
            }
          }
        }

This tells the AI how to structure the response, allowing you to programmatically render the data in your application without additional parsing.

Best Practice: Include Descriptive Guidance

Notice how each field includes descriptive guidance after the data type (e.g., "string - concise overview of current EV market trends"). These descriptions help the AI understand exactly what content to generate for each field.

Only add descriptive guidance to primitive values (strings, numbers, and booleans), not to arrays or objects themselves. For example, add descriptions to array elements (["string - specific obstacles facing the industry"]) rather than to the array declaration.

Adding specific guidance for each primitive field significantly improves the quality and relevance of the generated content. Be as specific as possible about what you want in each field, including tone, length, focus areas, and any other requirements.

Code Examples

# Request new content with data structure
curl -X POST https://trendifi.app/api/v1/content \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "topic": "Tesla stock performance",
  "data_structure": {
    "market_summary": {
      "price_change": "number - percentage change in stock price over last 30 days",
      "trading_volume": "number - average daily trading volume in millions",
      "key_metrics": ["string - important financial indicators with current values"]
    },
    "analysis": {
      "short_term_outlook": "string - 1-2 paragraph analysis of 3-month prospects",
      "long_term_outlook": "string - 1-2 paragraph analysis of 1-year prospects",
      "risk_factors": ["string - specific risks that could impact stock performance"]
    },
    "recommendations": ["string - actionable investment advice based on the analysis"]
  }
}'

# Response
{
  "request_id": "req_8f7d6e5c4b3a2910", 
  "status": "processing", 
  "created_at": "2025-05-30T14:32:10Z"
}

Response

The POST /content endpoint returns a response with a request ID that you can use to check the status of your content request and retrieve the results when processing is complete.

Response Fields

FieldTypeDescription
request_idstringUnique identifier for the content request
statusstringCurrent status of the request ("processing")
created_atstringISO 8601 timestamp when the request was created

Example Response

{
  "request_id": "ins_8f7d6e5c4b3a2910",
  "status": "processing",
  "created_at": "2023-09-15T14:32:10Z"
}

Error Handling

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 CodeDescription
200 OKThe request was successful
400 Bad RequestThe request was invalid or missing required parameters
401 UnauthorizedInvalid or missing API key
402 Payment RequiredAccount has insufficient tokens (0 tokens in balance)
404 Not FoundThe requested resource does not exist
405 Method Not AllowedThe HTTP method used is not supported for this endpoint (e.g., using GET instead of POST)
429 Too Many RequestsRate limit exceeded
500 Internal Server ErrorAn 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"
  }
}

Error Codes

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 CodeDescriptionHTTP Status
missing_topicNo topic was provided in the request400
missing_data_structureNo data structure was provided for a custom_json format request400
invalid_data_structureThe data structure provided is invalid or malformed400
unauthorizedInvalid or missing API key401
insufficient_tokensThe account does not have enough tokens to process the request402
not_foundThe specified resource (content/insight) ID does not exist404
content_not_foundThe specified content ID does not exist (legacy code)404
endpoint_not_foundThe requested API endpoint does not exist404
incorrect_methodThe HTTP method used is not supported for this endpoint405
rate_limit_exceededThe API rate limit has been exceeded429
internal_server_errorAn unexpected error occurred on the server500

Next Steps

Polling for Results

Content generation is an asynchronous process. After submitting your request, use the GET /content/:id endpoint to check status and retrieve results when processing is complete. For detailed polling strategies and implementation examples, see the GET endpoint documentation.