# Server mode

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

{% hint style="info" %}

* Float16 CLI installed
* Logged into Float16 account
* VSCode or preferred text editor recommended
  {% endhint %}

## Step 1 : Prepare Your Script

<https://github.com/float16-cloud/examples/tree/main/official/deploy/fastapi-helloworld>

(server.py)

```python
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)

```python
def say_hello():
    return "hello"
    
def say_world():
    return "world"
```

{% hint style="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"
  {% endhint %}

## Step 2 : Create project

```
float16 project create --instance h100
```

### Resulting Files

* `float16.conf`: Contains your project ID
* `requirements.txt`: Initially empty

{% hint style="info" %}
If you cannot create new project, [learn more](https://docs.float16.cloud/getting-started/faq#why-cant-i-create-a-new-project)
{% endhint %}

## Step 3 : Deploy Script

```
float16 deploy server.py
```

After successful deployment, you'll receive:

* Function Endpoint
* Server Endpoint
* API Key

**Example:**

<pre><code><strong>Function Endpoint: http://api.float16.cloud/task/run/function/x7x2DFl8zU   
</strong>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"
</code></pre>

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

<figure><img src="https://3153350778-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F06IkMLrrm1ptUT8449HF%2Fuploads%2F1lLWSLfQEF8iZ3YoDuHi%2Fimage.png?alt=media&#x26;token=88703111-cdf8-4d07-9887-16ed98ddf9d4" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
To understand the differences between function and server modes, refer to [the dedicated section](https://docs.float16.cloud/getting-started/quick-start/mode#deploy-mode).
{% endhint %}

{% hint style="success" %}
Congratulations! You've successfully use your first server mode on Float16's serverless GPU platform.
{% endhint %}

## Explore More&#x20;

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

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Hello World</strong></td><td>Launch your first serverless GPU function and kickstart your journey.</td><td><a href="hello-world">hello-world</a></td></tr><tr><td><strong>Install new library</strong></td><td>Enhance your toolkit by adding new libraries tailored to your project needs.</td><td><a href="install-new-library">install-new-library</a></td></tr><tr><td><strong>Copy output from remote</strong></td><td>Efficiently transfer computation results from remote to your local storage.</td><td><a href="s3-copy-output-from-remote">s3-copy-output-from-remote</a></td></tr><tr><td><strong>Deploy FastAPI Helloworld</strong></td><td>Quick start to deploy FastAPI without change the code.</td><td><a href="server-mode">server-mode</a></td></tr><tr><td><strong>Upload and Download via CLI and Website</strong></td><td>Direct upload and download file(s) to server.</td><td><a href="direct-upload-and-download">direct-upload-and-download</a></td></tr><tr><td><strong>More examples</strong></td><td>Open source from community and Float16 team.</td><td><a href="etc.">etc.</a></td></tr></tbody></table>

Happy coding with Float16 Serverless GPU!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.float16.cloud/getting-started/serverless-gpu/tutorials/server-mode.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
