> ## Documentation Index
> Fetch the complete documentation index at: https://docs.synapsai.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Gradio / FastAPI integration

> Build a web demo that proxies requests to SynapsAI Cloud from FastAPI or Gradio

Expose a small web demo that forwards user input to SynapsAI Cloud. **Never embed API keys in client-side JavaScript** — keep the key on the server.

## FastAPI

```python theme={null}
from fastapi import FastAPI, Request
from synapsai import SynapsAI

app = FastAPI()
client = SynapsAI()  # reads SYNAPSAI_API_KEY from the environment

@app.post("/generate")
async def generate(req: Request):
    body = await req.json()
    prompt = body.get("prompt", "")
    resp = client.chat.completions.create(
        model="<YOUR_MODEL_ID>",
        messages=[{"role": "user", "content": prompt}],
        max_tokens=200,
    )
    return {"text": resp.choices[0].message.content}
```

Run with `uvicorn main:app --reload`.

## Gradio

```python theme={null}
import gradio as gr
from synapsai import SynapsAI

client = SynapsAI()

def generate(prompt: str) -> str:
    resp = client.chat.completions.create(
        model="<YOUR_MODEL_ID>",
        messages=[{"role": "user", "content": prompt}],
        max_tokens=200,
    )
    return resp.choices[0].message.content

demo = gr.Interface(fn=generate, inputs="text", outputs="text", title="SynapsAI Demo")
demo.launch()
```

<Tip>
  For streaming UIs, pass `stream=True` and yield partial tokens. See [Streaming](/guides/streaming).
</Tip>
