Skip to content

Files

Latest commit

 

History

History

server

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

SwiftChat Backend API

The SwiftChat backend API is implemented using Python language and the FastAPI framework. It is packaged as a Docker image using aws-lambda-adapter and deployed to AWS App Runner or AWS Lambda for execution.

API Reference

API Schema

First, please configure you API URL and API Key like:

export API_URL=<API URL>
export API_KEY=<API Key>
  1. /api/converse

    curl -N "${API_URL}/api/converse" \
    --header 'Content-Type: application/json' \
    --header "Authorization: Bearer ${API_KEY}" \
    --data '{
      "messages": [
        {
          "role": "user",
          "content": [
            {
              "text": "Hi"
            }
          ]
        }
      ],
      "modelId": "anthropic.claude-3-5-sonnet-20240620-v1:0",
      "region": "us-west-2"
    }'

    This API is used to implement streaming conversations, and it only returns the text and token usage for display.

    The messages under body fully complies with the messages structure specification in Amazon Bedrock converse stream API. You can also add image or document according to the specification to support multimodal conversations.

  2. /api/converse/v2

    curl -N "${API_URL}/api/converse" \
    --header 'Content-Type: application/json' \
    --header "Authorization: Bearer ${API_KEY}" \
    --data '{
      "messages": [
        {
          "role": "user",
          "content": [
            {
              "text": "Hi"
            }
          ]
        }
      ],
      "modelId": "anthropic.claude-3-5-sonnet-20240620-v1:0",
      "region": "us-west-2",
      "enableThinking": false,
      "system": [
        "text": "your system prompt"
      ]
    }'

    This API is used to implement streaming conversations for v2, and it returns the raw Amazon Bedrock response json string, you need to parse it for display.

    The messages under body fully complies with the messages structure specification in Amazon Bedrock converse stream API. You can also add image or document according to the specification to support multimodal conversations.

  3. /api/image

    curl "${API_URL}/api/image" \
    --header 'Content-Type: application/json' \
    --header "Authorization: Bearer ${API_KEY}" \
    --data '{
      "prompt": "Beautiful countryside",
      "modelId": "stability.stable-image-core-v1:0",
      "region": "us-west-2",
      "width": "1024",
      "height": "1024"
    }'

    This API is used to generate images and returns a base64 encoded string of the image.

  4. /api/models

    curl "${API_URL}/api/models" \
    --header 'Content-Type: application/json' \
    --header 'accept: application/json' \
    --header "Authorization: Bearer ${API_KEY}" \
    --data '{
      "region": "us-west-2"
    }'

    This API is used to get a list of all streaming-supported text models and image generation models in the specified region.

  5. /api/upgrade

    curl "${API_URL}/api/upgrade" \
    --header 'Content-Type: application/json' \
    --header 'accept: application/json' \
    --header "Authorization: Bearer ${API_KEY}"

    This API is used to get the new version of SwiftChat for Android and macOS App updates.

API Code Reference