Server mode
Get Endpoint via Float16
This tutorial guides you through deploying a simple FastAPI "Hello World" application using Float16's deployment mode.
Step 1 : Prepare Your Script
https://github.com/float16-cloud/examples/tree/main/official/deploy/fastapi-helloworld
(server.py)
import os
import uvicorn
import asyncio
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from utils import *
app = FastAPI()
@app.get("/hello")
async def read_root():
return {"message": f"{say_hello() say_world()}"}
async def main():
config = uvicorn.Config(
app, host="0.0.0.0", port=int(os.environ["PORT"])
)
server = uvicorn.Server(config)
await server.serve()
(utils.py)
def say_hello():
return "hello"
def say_world():
return "world"
Step 2 : Create project
float16 project create --instance h100
Resulting Files
float16.conf
: Contains your project IDrequirements.txt
: Initially empty
Step 3 : Deploy Script
float16 deploy server.py
After successful deployment, you'll receive:
Function Endpoint
Server Endpoint
API Key
Example:
Function Endpoint: http://api.float16.cloud/task/run/function/x7x2DFl8zU
Server Endpoint: http://api.float16.cloud/task/run/server/x7x2DFl8zU
API Key: float16-r-QoZU7uNlgDIFJ5IMrBtOCjuzVBlC
## curl
curl -X GET "{FUNCTION-URL}/hello" -H "Authorization: Bearer {FLOAT16-ENDPOINT-TOKEN}"
curl -X GET "http://api.float16.cloud/task/run/function/x7x2DFl8zU/hello" -H "Authorization: Bearer float16-r-QoZU7uNlgDIFJ5IMrBtOCjuzVBlC"
Step 4 : Endpoint Request
Use the provided endpoints with the API key (bearer token) to make requests.
Endpoint Request Example:
Path:
/hello
Expected Response:
{"message": "Hello World!"}
Congratulations! You've successfully use your first server mode on Float16's serverless GPU platform.
Explore More
Learn how to use Float16 CLI for various use cases in our tutorials.
Happy coding with Float16 Serverless GPU!
Last updated