- Building Demos
- Server
New to Gradio? Start here: Getting Started
See the Release History
To install Gradio from main, run the following command:
pip install https://gradio-builds.s3.amazonaws.com/15ce43720d1611f44e4661c74d604eabe0d04daf/gradio-6.28.0-py3-none-any.whl*Note: Setting share=True in launch() will not work.
Server
gradio.Server(···)Description
Server is the Gradio API engine exposed on a FastAPI application (Server mode). It inherits from FastAPI, so all standard FastAPI methods (.get(), .post(), .add_middleware(), .include_router(), etc.) work directly on this instance.
New methods added on top of FastAPI: api(): Decorator to register a Gradio API endpoint with queue, SSE streaming, and concurrency control. mcp: Namespace with .tool(), .resource(), and .prompt() decorators to tag functions with MCP metadata. launch(): Creates an internal Blocks, registers deferred API endpoints, and starts the server.
Example Usage
from gradio import Server
app = Server()
@app.api(name="hello")
def hello(name: str) -> str:
return f"Hello {name}"
@app.get("/")
def root():
return {"message": "Hello World"}
app.launch()Initialization
Parameters
openapi_url: str | None
openapi_url: str | Nonedefault
= "/openapi.json"The URL path for the OpenAPI schema. Set to None to disable.
openapi_tags: list[dict[str, Any]] | None
openapi_tags: list[dict[str, Any]] | Nonedefault
= NoneTags for organizing endpoints in the OpenAPI docs.
docs_url: str | None
docs_url: str | Nonedefault
= "/docs"The URL path for the Swagger UI docs. Set to None to disable.
root_path_in_servers: bool
root_path_in_servers: booldefault
= TrueWhether to include root_path in the OpenAPI servers field.
responses: dict[int | str, dict[str, Any]] | None
responses: dict[int | str, dict[str, Any]] | Nonedefault
= NoneAdditional responses for the OpenAPI schema.
Demos
Methods
gradio.Server.api(···)Description %20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
Decorator to register a function as a Gradio API endpoint. <br> Goes through Gradio's queue with concurrency control and SSE streaming.
Parameters