OpenAI Quickstart
In this tutorial, you'll learn how to build an interactive AI application and deploy it to the cloud in just 9 lines of code.
Tutorial
1. Select the DBOS AI Starter
Visit https://console.dbos.dev/launch and select the DBOS AI Starter. When prompted, create a database for your app with default settings.
2. Connect to GitHub and Deploy to DBOS Cloud
To ensure you can easily update your project after deploying it, DBOS will create a GitHub repository for you. You can deploy directly from that GitHub repository to DBOS Cloud.
First, sign in to your GitHub account. Then, enter your OpenAI API key as an application secret. You can obtain an API key here. This key is securely stored and used by your app to make requests on your behalf to the OpenAI API. Then, set your repository name and whether it should be public or private.
Next, click "Create GitHub Repo and Deploy" and DBOS will clone a copy of the source code into your GitHub account, then deploy your project to DBOS Cloud. In less than a minute, your app should deploy successfully.
3. View Your Application
At this point, your new AI application is running in the cloud.
It's implemented in just 9 lines of code—to see them, visit your new GitHub repository and open app/main.py
.
This app ingests a document (Paul Graham's essay "What I Worked On") and answers questions about it using RAG.
Click on the URL to see it answer a question!
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from fastapi import FastAPI
from dbos import DBOS
app = FastAPI()
DBOS(fastapi=app)
documents = SimpleDirectoryReader("data").load_data()
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
@app.get("/")
def get_answer():
response = query_engine.query("What did the author do growing up?")
return str(response)
4. Start Building
To start building, edit your application on GitHub (source code is in app/main.py
), commit your changes, then press "Deploy From GitHub" on your applications page to see your changes reflected in the live application.
Not sure where to start? Try changing the question the app asks and see it give new answers! Or, if you're feeling adventerous, build an interface to ask your own questions.
Next Steps
Next, check out how DBOS can help you build resilient AI applications at scale:
- Use durable execution to write crashproof workflows.
- Read "Why DBOS?" to learn how DBOS works under the hood.
- Want to build a more complex app? Check out the AI-Powered Slackbot, Document Detective, or LLM-Powered Chatbot.
Running It Locally
You can also run your application locally for development and testing.
1. Git Clone Your Application
Clone your application from git and enter its directory.
git clone <your-git-url>
cd dbos-ai-starter
2. Set up a virtual environment
Create a virtual environment and install dependencies.
- macOS or Linux
- Windows (PowerShell)
- Windows (cmd)
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python3 -m venv .venv
.venv\Scripts\activate.ps1
pip install -r requirements.txt
python3 -m venv .venv
.venv\Scripts\activate.bat
pip install -r requirements.txt
3. Install the DBOS Cloud CLI
The Cloud CLI requires Node.js 20 or later.
Instructions to install Node.js
- macOS or Linux
- Windows
Run the following commands in your terminal:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm install 22
nvm use 22
Download Node.js 20 or later from the official Node.js download page and install it.
After installing Node.js, create the following folder: C:\Users\%user%\AppData\Roaming\npm
(%user%
is the Windows user on which you are logged in).
Run this command to install it.
npm i -g @dbos-inc/dbos-cloud@latest
4. Connect Your Application to Postgres
Under the hood, DBOS uses Postgres for scheduling, so you need to connect your app to a Postgres database—you can use a DBOS Cloud database, a Docker container, or a local Postgres installation:
Instructions to set up Postgres
- Use Cloud Postgres
- Launch Postgres with Docker
- Install Postgres
You can connect your local application to a Postgres database hosted in DBOS Cloud.
First, set a password for your DBOS Cloud database:
dbos-cloud db reset-password
Then connect your local app to your cloud database. When prompted, enter the password you just set.
dbos-cloud db local
- macOS
- Linux
- Windows (PowerShell)
- Windows (cmd)
You can install Docker on macOS through Docker Desktop.
Then, run this script to launch Postgres in a Docker container:
export PGPASSWORD=dbos
# Docker may require sudo -E
python3 start_postgres_docker.py
Follow the Docker Engine installation page to install Docker on several popular Linux distributions.
Then, run this script to launch Postgres in a Docker container:
export PGPASSWORD=dbos
# Docker may require sudo -E
python3 start_postgres_docker.py
You can install Docker on Windows through Docker Desktop.
Then, run this script to launch Postgres in a Docker container:
$env:PGPASSWORD = "dbos"
python3 start_postgres_docker.py
You can install Docker on Windows through Docker Desktop.
Then, run this script to launch Postgres in a Docker container:
set PGPASSWORD=dbos
python3 start_postgres_docker.py
If successful, the script should print Database started successfully!
- macOS
- Linux
- Windows (PowerShell)
- Windows (cmd)
Follow this guide to install Postgres on macOS.
Then, set the PGPASSWORD
environment variable to your Postgres password:
export PGPASSWORD=<your-postgres-password>
Follow these guides to install Postgres on popular Linux distributions.
Then, set the PGPASSWORD
environment variable to your Postgres password:
export PGPASSWORD=<your-postgres-password>
Follow this guide to install Postgres on Windows.
Then, set the PGPASSWORD
environment variable to your Postgres password:
$env:PGPASSWORD = "<your-postgres-password>"
Follow this guide to install Postgres on Windows.
Then, set the PGPASSWORD
environment variable to your Postgres password:
set PGPASSWORD=<your-postgres-password>
Alternatively, if you already have a Postgres database, update dbos-config.yaml
with its connection information.
5. Start Your Appliation
Export your OpenAI API key to your application.
Next, start your application with dbos start
, then visit http://localhost:8000
to see it!
export OPENAI_API_KEY=<your key>
dbos start