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.
First, please configure you API URL
and API Key
like:
export API_URL=<API URL>
export API_KEY=<API Key>
-
/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 addimage
ordocument
according to the specification to support multimodal conversations. -
/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.
-
/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.
-
/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.
-
Client code: bedrock-api.ts
-
Server code: main.py