# How to Prepare OpenAPI Specification for Your FabriXAI Agent
OpenAPI specification, also known as Swagger file, is a widely used format for documenting and testing APIs using YAML or JSON. This guide will help you prepare an OpenAPI specification (Swagger file) that describes how your FabriXAI agent's API works, using either a ready-made template or build from scratch:
- Option 1: Prepare an OpenAPI Specification from Template
- Option 2: Build an OpenAPI Specification from Scratch
# Prepare an OpenAPI Specification from Template
FabriXAI supports two types of agents: WebApp and Chatbot. To learn more about the differences, please refer to What Are AI Agents?.
Download a Swagger template for your agent type:
Open the downloaded Swagger template in a text editor or the Swagger Editor (opens new window).
Update the input fields based on your agent’s configured inputs:
- For WebApp agents, please locate the following section and update accordingly:
path > /completion-messages > post > requestBody > content > application/json > schema > properties > inputs > properties
- For Chatbot agents, please locate the following section and update accordingly:
path > /chat-messages > post > requestBody > content > application/json > schema > properties > inputs > properties
- For WebApp agents, please locate the following section and update accordingly:
Example: If your agent uses the fields
key_skills_expertise
andproject_name
under User Inputs, you would update the Swagger file like this:inputs: type: object description: Contains key/value pairs for text input. properties: key_skills_expertise: type: string description: The key skill or expertise that needed for the project to be processed. project_name: type: string description: The name of project to be processed.
# Build an OpenAPI Specification from Scratch
If you prefer more flexibility or need to support custom behavior, you can also build your Swagger file from scratch instead of starting from a template. This is useful for advanced customization or when working with unique agent configurations.
Define the Basic Structure
Create a new YAML file (e.g.
swagger.yaml
) and add this basic structure:openapi: 3.0.0 info: title: API Documentation version: 1.0.0 servers: - url: https://console.fabrixai.com/v1 description: FabriXAI API Server components: securitySchemes: ApiKeyAuth: type: apiKey in: header name: Authorization description: "Use the API Key in the 'Authorization' header as 'Bearer {API_KEY}'" security: - ApiKeyAuth: []
Define API Endpoints (Paths)
Now you’ll describe what your API can do by adding endpoints under the
paths
section. Each endpoint represents an action your agent can perform, like generating a message or uploading a file.Let’s start with a common example: generating a completion message (used by WebApp agents). This tells the system how to process and respond to a request.
Here’s a sample section you can copy and modify in your Swagger file:
paths: /completion-messages: post: summary: Create Completion Message description: Send a request to generate a message. security: - ApiKeyAuth: [] # This ensures this endpoint requires authentication requestBody: required: true content: application/json: schema: type: object properties: inputs: type: object description: Contains key/value pairs for text input. properties: query: type: string description: The input text to be processed. response_mode: type: string description: Response mode (streaming or blocking). example: blocking user: type: string description: User identifier for tracking. example: user responses: '200': description: Success content: application/json: schema: type: object properties: message_id: type: string description: Unique message ID conversation_id: type: string description: Conversation ID answer: type: string description: Generated response text '400': description: 'invalid_param: abnormal parameter input; app_unavailable: App configuration unavailable; provider_not_initialize: no available model credential configuration; provider_quota_exceeded: model invocation quota insufficient; model_currently_not_support: current model unavailable; completion_request_error: text generation failed;' '404': description: Conversation does not exist '500': description: Internal server error
TIP
WebApp vs Chatbot agents Configuration:
- Use
/completion-messages
for WebApp agents. - Use
/chat-messages
for Chatbot agents.
Remember: You’ll need to replace the example input fields (query, etc.) with the actual inputs your agent uses. See the next section for how to do this.
- Use
Add Custom Inputs
Just like in the template method, update the
inputs
section based on your agent’s configured fields.inputs: type: object description: Contains key/value pairs for text input. properties: key_skills_expertise: type: string description: The key skill or expertise that needed for the project to be processed. project_name: type: string description: The name of project to be processed.
Add Additional Endpoints (Optional)
You can document more endpoints as needed. You may refer to Agent Builder > Integrations > API page of your AI agent for the full list of examples.
Some useful ones include:
POST /files/upload
- File UploadPOST /completion-messages/{task_id}/stop
– Stop CompletionPOST /chat-messages/{task_id}/stop
– Stop ChatGET /parameters
– Get Agent ParametersPOST /messages/{message_id}/feedbacks
– Message FeedbackGET /messages/{message_id}/suggested
– Suggested QuestionsDELETE /conversations/{conversation_id}
– Delete ConversationPUT /conversations/{conversation_id}/name
– Rename ConversationGET /meta
– Get Conversation MetadataPOST /text-to-audio
– Text to AudioPOST /audio-to-text
– Speech to Text
Validate Your Swagger File
- Open the Swagger Editor (opens new window).
- Copy and paste your YAML file.
- Fix any syntax or structure errors shown in the editor.
Test Your API Using Swagger UI
- Go to Swagger Editor (opens new window).
- Click "Try it out" on any endpoint.
- Enter your API Key in the Authorization field:
- Format:
Bearer {api_key}
- Replace
{api_key}
with your actual API key - If you don’t have one, follow the Step-by-Step Guide to Integration
- Format:
- Fill out the request body fields (e.g.,
inputs
,response_mode
,user
) - Click "Execute" to send the request and view the response.