Skip to main content
The Gradio JavaScript client makes it easy to use any Gradio app as an API from Node.js or browser environments. You can call Gradio apps hosted on Hugging Face Spaces, your own servers, or anywhere else.

Installation

Install via npm for Node.js projects (requires Node.js 18.0.0 or higher):

Quick start

Here’s a simple example using the Whisper transcription Space:

Connecting to apps

Connect to Hugging Face Spaces

Connect to a Gradio app by passing the Space name:

Connect to private Spaces

For private Spaces, pass your Hugging Face token:
Get your token at https://huggingface.co/settings/tokens.

Connect to custom URLs

If your app is running on your own server:

Connect with authentication

If the app requires username and password:

Duplicate a Space for unlimited usage

For unlimited usage without rate limits, duplicate the Space:

Configure hardware

Customize the hardware and timeout settings:
If the original Space uses GPUs, your duplicated Space will be billed accordingly. Spaces automatically sleep after 5 minutes of inactivity.

Inspect API endpoints

View available endpoints and their parameters:
You can also click “Use via API” in the app footer to view the API page in your browser.

Make predictions

Basic prediction

Call .predict() with the endpoint name and arguments:

Multiple parameters

Pass multiple arguments as an array:

File inputs

For file inputs, pass a Buffer, Blob, or File:

Using events

For endpoints that return results over time or for monitoring job status, use the event interface:

Monitor status

Enable status updates by setting the events option:
Status objects include:
  • status: Human-readable status (pending, generating, complete, error)
  • code: Detailed Gradio status code
  • position: Position in queue
  • queue_size: Total queue size
  • eta: Estimated completion time
  • success: Whether job completed successfully
  • time: When status was generated

Cancel jobs

Cancel queued or running jobs:

Generator endpoints

For endpoints that yield multiple values, iterate over the results:

Cancel generator endpoints

Cancel iterative outputs to stop generation:

Complete example

Here’s a complete HTML example:

Next steps

Python client

Use Gradio apps as APIs from Python

FastAPI integration

Integrate Gradio client with FastAPI