1. Building Demos
  2. 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
🔗
debug: bool
default = False

Enable debug mode for detailed error tracebacks.

🔗
title: str
default = "FastAPI"

The title of the API, shown in the OpenAPI docs.

🔗
summary: str | None
default = None

A short summary of the API.

🔗
description: str
default = ""

A longer description of the API. Supports Markdown.

🔗
version: str
default = "0.1.0"

The version of the API.

🔗
openapi_url: str | None
default = "/openapi.json"

The URL path for the OpenAPI schema. Set to None to disable.

🔗
openapi_tags: list[dict[str, Any]] | None
default = None

Tags for organizing endpoints in the OpenAPI docs.

🔗
servers: list[dict[str, Any]] | None
default = None

Server URLs for the OpenAPI schema.

🔗
dependencies: Any
default = None

Global dependencies applied to all routes.

🔗
default_response_class: Any
default = None

The default response class for routes.

🔗
redirect_slashes: bool
default = True

Whether to redirect trailing slashes.

🔗
docs_url: str | None
default = "/docs"

The URL path for the Swagger UI docs. Set to None to disable.

🔗
redoc_url: str | None
default = "/redoc"

The URL path for the ReDoc docs. Set to None to disable.

🔗
middleware: Any
default = None

List of middleware to add to the server.

🔗
exception_handlers: Any
default = None

Custom exception handlers.

🔗
on_startup: Any
default = None

List of startup event handlers. Prefer lifespan instead.

🔗
on_shutdown: Any
default = None

List of shutdown event handlers. Prefer lifespan instead.

🔗
lifespan: Any
default = None

An async context manager for startup/shutdown lifecycle.

🔗
terms_of_service: str | None
default = None

URL to the terms of service.

🔗
contact: dict[str, Any] | None
default = None

Contact information dict for the API.

🔗
license_info: dict[str, Any] | None
default = None

License information dict for the API.

🔗
root_path: str
default = ""

A path prefix for the app when behind a proxy.

🔗
root_path_in_servers: bool
default = True

Whether to include root_path in the OpenAPI servers field.

🔗
responses: dict[int | str, dict[str, Any]] | None
default = None

Additional responses for the OpenAPI schema.

🔗
callbacks: Any
default = None

OpenAPI callback definitions.

🔗
webhooks: Any
default = None

OpenAPI webhook definitions.

🔗
deprecated: bool | None
default = None

Mark all routes as deprecated.

🔗
include_in_schema: bool
default = True

Whether to include all routes in the OpenAPI schema.

🔗
generate_unique_id_function: Any
default = None

Custom function to generate unique operation IDs.

🔗
separate_input_output_schemas: bool
default = True

Whether to generate separate input/output schemas.

🔗
extra: Any

Demos

Methods

api

gradio.Server.api(···)

Description

Decorator to register a function as a Gradio API endpoint. <br> Goes through Gradio's queue with concurrency control and SSE streaming.

Parameters
🔗
fn: Callable | None
default = None
🔗
name: str | None
default = None
🔗
description: str | None
default = None
🔗
concurrency_limit: int | None | Literal['default']
default = "default"
🔗
concurrency_id: str | None
default = None
🔗
queue: bool
default = True
🔗
batch: bool
default = False
🔗
max_batch_size: int
default = 4
🔗
api_visibility: Literal['public', 'private', 'undocumented']
default = "public"
🔗
time_limit: int | None
default = None
🔗
stream_every: float
default = 0.5

launch

gradio.Server.launch(···)

Description

Launch the Gradio API server (Server mode). <br> Parameters match ``Blocks.launch()``; see that method for full descriptions. <br>

Parameters
🔗
inline: bool | None
default = None
🔗
inbrowser: bool
default = False
🔗
share: bool | None
default = None
🔗
debug: bool
default = False
🔗
max_threads: int
default = 40
🔗
auth: Callable[[str, str], bool] | tuple[str, str] | list[tuple[str, str]] | None
default = None
🔗
auth_message: str | None
default = None
🔗
prevent_thread_lock: bool
default = False
🔗
show_error: bool
default = False
🔗
server_name: str | None
default = None
🔗
server_port: int | None
default = None
🔗
height: int
default = 500
🔗
width: int | str
default = "100%"
🔗
favicon_path: str | Path | None
default = None
🔗
ssl_keyfile: str | None
default = None
🔗
ssl_certfile: str | None
default = None
🔗
ssl_keyfile_password: str | None
default = None
🔗
ssl_verify: bool
default = True
🔗
quiet: bool
default = False
🔗
run_history: bool | None
default = None
🔗
allowed_paths: list[str] | None
default = None
🔗
blocked_paths: list[str] | None
default = None
🔗
root_path: str | None
default = None
🔗
app_kwargs: dict[str, Any] | None
default = None
🔗
state_session_capacity: int
default = 10000
🔗
share_server_address: str | None
default = None
🔗
share_server_protocol: Literal['http', 'https'] | None
default = None
🔗
share_server_tls_certificate: str | None
default = None
🔗
auth_dependency: Callable[[fastapi.Request], str | None | Awaitable[str | None]] | None
default = None
🔗
max_file_size: str | int | None
default = None
🔗
enable_monitoring: bool | None
default = None
🔗
strict_cors: bool
default = True
🔗
node_server_name: str | None
default = None
🔗
node_port: int | None
default = None
🔗
ssr_mode: bool | None
default = None
🔗
pwa: bool | None
default = None
🔗
mcp_server: bool | None
default = None
🔗
i18n: I18n | None
default = None
🔗
theme: Theme | str | None
default = None
🔗
css: str | None
default = None
🔗
css_paths: str | Path | list[str | Path] | None
default = None
🔗
js: str | Literal[True] | None
default = None
🔗
head: str | None
default = None
🔗
head_paths: str | Path | list[str | Path] | None
default = None
🔗
num_workers: int | None
default = None