Server mode

Get Endpoint via Float16

This tutorial guides you through deploying a simple FastAPI "Hello World" application using Float16's deployment mode.

circle-info
  • Float16 CLI installed

  • Logged into Float16 account

  • VSCode or preferred text editor recommended

Step 1 : Prepare Your Script

https://github.com/float16-cloud/examples/tree/main/official/deploy/fastapi-helloworldarrow-up-right

(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)

circle-info
  • Save the script in a selected folder

  • Navigate to the folder in your terminal

  • Ensure the port is set to "port=int(os.environ['PORT'])"

  • Ensure the server is serve with "async def main"

Step 2 : Create project

Resulting Files

  • float16.conf: Contains your project ID

  • requirements.txt: Initially empty

circle-info

If you cannot create new project, learn more

Step 3 : Deploy Script

After successful deployment, you'll receive:

  • Function Endpoint

  • Server Endpoint

  • API Key

Example:

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!"}

circle-info

To understand the differences between function and server modes, refer to the dedicated section.

circle-check

Explore More

Learn how to use Float16 CLI for various use cases in our tutorials.

Happy coding with Float16 Serverless GPU!

Last updated