How to Deploy the OpenBB REST API in Production Using Uvicorn

Deploy the OpenBB REST API in production by installing the openbb-platform-api package and launching it via the openbb-api CLI entry point or directly with uvicorn, configuring multi-worker processes, SSL certificates, and host binding for secure, high-performance access.

The OpenBB REST API (also referred to as the OpenBB Platform API) is a FastAPI-based application housed in the OpenBB-finance/OpenBB repository. When you deploy the OpenBB REST API in production using Uvicorn, you leverage an ASGI server configuration that supports multiple workers, HTTPS encryption, and custom application factories to handle concurrent financial data requests reliably.

Installation and Entry Points

Install the API as a standalone component or as part of the full OpenBB distribution:

pip install openbb-platform-api

The package declares a console script in openbb_platform/extensions/platform_api/pyproject.toml that serves as the primary launcher:

[tool.poetry.scripts]
openbb-api = "openbb_platform_api.main:main"

This entry point imports the FastAPI instance from openbb_platform_api.main:app and delegates execution to Uvicorn.

Launch Methods

You have three primary methods to start the server in production environments.

Using the openbb-api Helper Script

The recommended approach for standard deployments uses the provided CLI wrapper:

openbb-api --host 0.0.0.0 --port 8080 --workers 4

Under the hood, the launch_api function in openbb_platform/extensions/platform_api/openbb_platform_api/main.py invokes:

uvicorn.run(f"{package_name}.main:app", host=host, port=port, **_kwargs)

This method automatically handles package discovery and passes through any Uvicorn-compatible arguments.

Running Uvicorn Directly

For environments requiring fine-grained control over the ASGI loop or HTTP parser, invoke Uvicorn directly:

uvicorn openbb_platform_api.main:app \
    --host 0.0.0.0 \
    --port 8080 \
    --workers 4 \
    --log-level info \
    --loop uvloop \
    --http httptools

Direct invocation bypasses the helper logic and allows you to specify performance-tuned event loops explicitly.

Serving a Custom FastAPI Application

If you maintain a custom FastAPI instance in a separate module, point the launcher to your factory function:

openbb-api --app my_app.py:create_app --factory

The --factory flag instructs the launcher that create_app is a callable returning a FastAPI instance, enabling custom middleware or router configurations.

Production Configuration Parameters

Configure the following arguments when you deploy the OpenBB REST API in production using Uvicorn to ensure security and scalability:

  • --host 0.0.0.0 – Binds to all network interfaces, required for Docker containers and external access.
  • --port – TCP port (default 6900).
  • --workers – Number of worker processes (recommend 2 or more for production; typically 2-4 x CPU cores).
  • --ssl_keyfile / --ssl_certfile – Paths to SSL certificate files for HTTPS termination.
  • --app – Module path to a custom FastAPI application (e.g., my_api:app).
  • --factory – Indicates the --app target is a factory function, not an instance.
  • --editable – Persists widgets.json to disk at runtime for modification.
  • --no-build – Skips widget generation if widgets.json is pre-generated.

All arguments are validated in openbb_platform/extensions/platform_api/openbb_platform_api/utils/api.py before being passed to the Uvicorn server.

Docker Deployment

The repository provides a production-ready image definition in build/docker/platformAPI.Dockerfile:

FROM python:3.10-slim-bookworm
WORKDIR /app
RUN pip install "openbb[all]"
RUN pip install openbb-platform-api
EXPOSE 6900
ENTRYPOINT ["openbb-api", "--host", "0.0.0.0"]

Build and run the container with custom worker settings:

docker build -t openbb-platform-api -f build/docker/platformAPI.Dockerfile .
docker run -d -p 8080:8080 --name openbb-api \
    -v $HOME/.openbb:/root/.openbb \
    openbb-platform-api \
    --port 8080 \
    --workers 4

Mount the -v $HOME/.openbb:/root/.openbb volume to persist API keys and user configurations outside the container.

Docker Compose Example

version: "3.8"
services:
  openbb-api:
    build:
      context: .
      dockerfile: build/docker/platformAPI.Dockerfile
    ports:
      - "8080:8080"
    volumes:
      - ./certs:/certs
      - $HOME/.openbb:/root/.openbb
    command: >-
      --port 8080
      --workers 4
      --ssl_keyfile /certs/server.key
      --ssl_certfile /certs/server.crt

Systemd Service Configuration

For bare-metal or VM deployments, create a systemd unit file to manage the process lifecycle:


# /etc/systemd/system/openbb-api.service

[Unit]
Description=OpenBB Platform API
After=network.target

[Service]
User=openbb
Group=openbb
WorkingDirectory=/opt/openbb
Environment="PATH=/opt/openbb/venv/bin"
ExecStart=/opt/openbb/venv/bin/openbb-api \
    --host 0.0.0.0 \
    --port 8080 \
    --workers 4
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

Enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable --now openbb-api

Verification and Health Checks

Once deployed, verify functionality through the auto-generated endpoints:

Test the widgets endpoint:

curl http://localhost:8080/widgets.json | jq .

If you launched with --editable, the widget configuration is written to the environment's assets/widgets.json path for runtime modification.

Summary

  • Install the API via pip install openbb-platform-api to access the openbb-api console script.
  • Deploy using the helper script for simplicity or Uvicorn directly for advanced ASGI tuning.
  • Secure production instances with --ssl_keyfile and --ssl_certfile for HTTPS.
  • Scale horizontally using --workers to match CPU core count, or orchestrate multiple containers behind a load balancer.
  • Persist configuration by mounting $HOME/.openbb in Docker or setting appropriate WorkingDirectory in systemd.

Frequently Asked Questions

What is the difference between using openbb-api and running uvicorn directly?

The openbb-api script is a convenience wrapper defined in openbb_platform/extensions/platform_api/pyproject.toml that discovers the correct package path and passes arguments to uvicorn.run(). Running uvicorn directly gives you explicit control over the Python path, event loops (--loop uvloop), and HTTP implementations (--http httptools) without intermediary logic, but requires you to specify the full module path openbb_platform_api.main:app.

How do I enable HTTPS for the OpenBB REST API?

Pass the --ssl_keyfile and --ssl_certfile arguments when launching the server. For the helper script: openbb-api --ssl_keyfile /path/to/key.pem --ssl_certfile /path/to/cert.pem. For direct Uvicorn execution, these map to the standard Uvicorn SSL configuration options. Both methods handle SSL termination at the application layer.

How many Uvicorn workers should I configure for production?

Set --workers to a value between 2 and 4 times the number of CPU cores available on the host. For example, on a 4-core machine, use --workers 4 or --workers 8. Uvicorn workers run as separate processes, allowing the OpenBB API to handle concurrent requests across multiple CPU cores without blocking the GIL.

Can I deploy a custom FastAPI application instead of the default OpenBB API?

Yes. Use the --app flag to specify a Python module and callable (e.g., custom_module:app), and include --factory if the callable is a function returning a FastAPI instance rather than the instance itself. This is handled by the argument parser in openbb_platform/extensions/platform_api/openbb_platform_api/utils/api.py, which dynamically imports your custom application before passing it to Uvicorn.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →