API

Each endpoint requires an API Bearer passed via headers or query parameters. This API is validated using dependency injection to ensure that requests are authorized.

This documentation thoroughly explains the purpose and functionality of each endpoint, including the models used for requests and responses. It also highlights key security features, including Cloudflare protection and containerized client data.


API Endpoints

Base URL:/api/v1

Read Main Endpoint

  • Endpoint: GET / https://backend.fana.ai/api/v1/

  • Summary: Returns a welcoming message from the API.

  • Response:

    {
      "msg": "Hello from FANA API V1"
    }
  • Description: This endpoint serves as the root and provides a basic acknowledgement that the API is operational.

  • Security: Protected by API Bearer Authentication.

1. All-in-one endpoint: Interact with LLM

  • Endpoint: POST /api/v1/interact-with-llm/

  • https://backend.fana.ai/api/v1/prediction/interact

  • Summary: This endpoint serves as the central hub for interacting with Fana AI's backend, offering text conversation, generating images, analyzing images via URLs, and processing image uploads, which send back a similar image with a description.

  • Description: Accepts multipart/form-data, either text, a file, or both. To use this endpoint, submit either 'text' as a text type or 'file' as a file type in the request.

  • Security: Protected by API Bearer Authentication.

  • Request Model: multipart/form-data

    • For this endpoint, we have 4 options: A. Conversational RAG: User's input text. For usual conversations and FAQs; B. Image Generation: NLP integrated which can be triggered with 174 triggers. C. Image Analysis to Generate Similar Image: The text must contain an image URL or image URL + user query that will be sent to the analyze-image module D. Upload Image and Generate Similar Image: Our LLM take this uploaded file, sends it to computer vision, and then to diffusion and it sends us a similar image with a description back.

    • chat_history(Optional): List of prior interactions to maintain context.

  • Response Model: LLMResponse

    • response: The LLM's text response could be a simple conversational text, an image-generated URL that we convert to image previews or an image description.

    • chat_history: Updated chat history including the current interaction.

How to Use This Endpoint

Example Postman Request:

POST: https://backend.fana.ai/api/v1/prediction/interact

Content-Type: Always use 'multipart/form-data' for text, file upload or both

  • Text Input:

    • Content-Type: multipart/form-data

    • Key: text

    • Type: text

    • Value: Your input text here

  • File Upload:

    • Content-Type: multipart/form-data

    • Key: file

    • Type: file

    • Value: Select a file to upload

  • Chat History:

    • Content-Type: multipart/form-data

    • Key: file

    • Type: file

    • Value: [{"role": "user", "content": "Hello"}, {"role": "assistant", "content": "Hi there! How can I assist you today?"}, {"role": "user", "content": "My name is Adolfo, nice to meet you"}, {"role": "assistant", "content": "Nice to meet you Adolfo, how can I help you today?."}]"

Note: Replace YOUR_BEARER_TOKEN_HERE with your actual bearer token.

Example cURL Request:

Text Conversation:

curl -X POST "https://backend.fana.ai/api/v1/interact/interact/" \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer YOUR_BEARER_TOKEN_HERE" \
-F "text=what is this image about?"

File Upload:

curl -X POST "https://backend.fana.ai/api/v1/interact/interact/" \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer YOUR_BEARER_TOKEN_HERE" \
-F "file=@path_to_your_file_here"

Chat History:

curl -X POST "https://backend.fana.ai/api/v1/interact/interact/" \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer YOUR_BEARER_TOKEN_HERE" \
-F "text=What is AImagine?" \
-F "chat_history=[{\"role\": \"user\", \"content\": \"Hello\"}, {\"role\": \"assistant\", \"content\": \"Hi there! How can I assist you today?\"}, {\"role\": \"user\", \"content\": \"My name is Adolfo, nice to meet you\"}, {\"role\": \"assistant\", \"content\": \"Nice to meet you Adolfo, how can I help you today?\"}]"

Note: Replace YOUR_BEARER_TOKEN_HERE with your actual bearer token.

2. Generate Image

  • Endpoint: POST api/v1/generate-image/ https://backend.fana.ai/api/v1/generate-image/

  • Summary: Generates images based on provided text prompts.

  • Security: Protected by API Bearer Authentication.

  • Request Model: ImageGenerationRequest

    • prompt: A string containing the text prompt for image generation.

  • Response Model: ImageGenerationResponse

    • image_html: A string containing HTML data of the generated image.

  • Description: This endpoint uses the language model to generate images that correspond to the provided text prompt. The output is an HTML string embedding the generated image.

3. Analyze Image

  • Endpoint: POST /api/v1/analyze-image/ https://backend.fana.ai/api/v1/analyze-image/

  • Summary: Analyzes an image from a given URL and returns analysis results.

  • Security: Protected by API Bearer Authentication.

  • Request Model: TextRequest

    • text: URL of the image to analyze.

  • Response: Plain text or JSON detailing the analysis results.

  • Description: Takes the URL of an uploaded image (usually provided by the upload-image endpoint) and analyzes its contents. The analysis results can be utilized to generate similar images by passing the descriptive data back to the generate-image endpoint. It can also take any image URL and send a description back.

4. Upload Image

  • Endpoint: POST /api/v1/upload-image/ https://backend.fana.ai/api/v1/upload-image/

  • Summary: Uploads an image to Azure Blob cloud service and returns a URL.

  • Security: Protected by API Bearer Authentication.

  • Request Model: multipart/form-data

  • Response Model: ImageUploadResponse

    • image_url: URL of the uploaded image.

  • Description: Users can upload an image file, which is then hosted on Azure Blob. The URL returned can be used for further processing, such as image analysis or to generate a similar image using the generate-image endpoint.



Last updated