Skip to main content

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.

Cloud Console Templates

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.

Deploy with GitHub

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.

Deploy with GitHub

Next Steps

Next, check out how DBOS can help you build resilient AI applications at scale:

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.

python3 -m venv .venv
source .venv/bin/activate
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

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

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

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

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