> For the complete documentation index, see [llms.txt](https://docs.openg2p.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.openg2p.org/products/registry/registry/developer-zone/developer-install/beneficiary-portal-api.md).

# Beneficiary Portal API

Developers can set up and run the OpenG2P Registry Beneficiary Portal API on their local machines. This guide outlines the steps to install it on a Linux-based laptop or desktop.

### Prerequisites

* Python3
* Git
* PostgreSQL

### Installation of Beneficiary Portal API

#### 1. Update system packages

Log in to your Linux server using SSH and update the package list and upgrade the existing packages:

```bash
sudo apt update
sudo apt upgrade -y
```

#### 2. Install dependencies

```bash
sudo apt install -y python3-pip python3-dev python3-venv build-essential libpq-dev
```

#### 3. Install and configure PostgreSQL

The Registry uses PostgreSQL as the database engine. Install PostgreSQL (if not already installed) and create a new database user and database.

```bash
sudo apt install -y postgresql
sudo su - postgres
psql
CREATE ROLE registryuser WITH LOGIN NOSUPERUSER CREATEDB CREATEROLE INHERIT REPLICATION CONNECTION LIMIT -1 PASSWORD 'password';
CREATE DATABASE registrydb WITH OWNER = registryuser CONNECTION LIMIT = -1;
exit
exit
```

#### 4. Clone the Registry APIs Repository

```bash
git clone https://github.com/OpenG2P/registry-platform/tree/develop/apis
```

#### 5. Install Python Libraries and Run the API

* Create a new Python virtual environment:

```bash
cd registry-platform/apis/openg2p-registry-bene-portal-api
python3 -m venv venv
```

* Activate the virtual environment:

```bash
source venv/bin/activate
```

* Install required Python packages:

```bash
python3 -m pip install \
    openg2p-fastapi-common \
    openg2p-registry-core \
    openg2p-registry-extensions \
    openg2p-registry-bene-portal-api \
    asyncpg \
    psycopg2
```

* Create a `.env` file:

```
REGISTRY_BENE_PORTAL_API_DB_DBNAME='registrydb'
REGISTRY_BENE_PORTAL_API_DB_HOSTNAME='localhost'
REGISTRY_BENE_PORTAL_API_DB_PORT='5432'
REGISTRY_BENE_PORTAL_API_DB_USERNAME='registryuser'
REGISTRY_BENE_PORTAL_API_DB_PASSWORD='password'
REGISTRY_BENE_PORTAL_API_HOST='0.0.0.0'
REGISTRY_BENE_PORTAL_API_PORT='8000'
```

* Run the API server:

```bash
gunicorn "main:app" --workers 1 --worker-class uvicorn.workers.UvicornWorker --bind 127.0.0.1:8000
```

### Verifying the Installation

Open the OpenAPI docs in your browser at `http://127.0.0.1:8000/docs`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.openg2p.org/products/registry/registry/developer-zone/developer-install/beneficiary-portal-api.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
