API Request/Response Formats
Understanding the correct format for API requests and responses is crucial for successful integration with Fewzen AI. This guide provides detailed information on the structure and data types used in our API communications.
General Format
Fewzen AI API uses JSON for both request bodies and response payloads. All API requests should include the following headers:
Content-Type: application/json
Authorization: Bearer YOUR_API_KEY
Replace YOUR_API_KEY with your actual Fewzen AI API key.
Request Formats
Chat Request Format
Example request body for initiating a chat:
{
"agent_id": "string",
"messages": [
{
"role": "user",
"content": "string"
}
],
"max_tokens": number,
"temperature": number
}
agent_id
: The ID of the AI agent to chat withmessages
: An array of message objects, each with a role and contentmax_tokens
: (Optional) Maximum number of tokens in the responsetemperature
: (Optional) Controls randomness in responses (0.0 to 1.0)
Response Formats
Success Response Format
Example success response for a chat request:
{
"id": "string",
"created": number,
"agent_id": "string",
"messages": [
{
"role": "assistant",
"content": "string"
}
]
}
id
: A unique identifier for this responsecreated
: Timestamp of when the response was generatedagent_id
: The ID of the agent that generated the responsemessages
: An array of message objects, typically containing the AI's response
Data Types
Fewzen AI API uses the following data types in requests and responses:
string
: A sequence of charactersnumber
: An integer or floating-point numberboolean
: true or falsearray
: An ordered list of valuesobject
: A collection of key-value pairsnull
: Represents a null or empty value
Best Practices
Validate Input
Always validate your input data before sending requests to ensure it matches the expected format and data types.
Handle Errors Gracefully
Implement proper error handling in your application to gracefully handle and log any API errors.
Use Appropriate Content-Type
Always set the Content-Type header to application/json for requests with JSON payloads.
Respect Rate Limits
Be mindful of API rate limits and implement appropriate throttling or queueing mechanisms in your application.
Ready to Start Making API Requests?
Now that you understand the request and response formats for the Fewzen AI API, you're ready to start integrating our powerful AI capabilities into your applications.
Explore API Endpoints