# Run your app on another host with one key

> Use thelastapi backend services from any external server, container, or platform by passing a single environment variable: VIBIZ_APP_KEY.

**You can use thelastapi backend services—database, sign-in, AI models, payments, email, and analytics—from any host using a single app key.** You do not need to host your frontend or application server on our platform to use the rest of the stack. Pass `VIBIZ_APP_KEY` to your container, virtual machine, or external host, and your code accesses every backend service immediately.

If you already have a deployment pipeline or prefer to run servers on your own infrastructure, this setup keeps your configuration minimal. One key provides access to serverless Postgres, an OpenAI-compatible gateway to models from OpenAI, Anthropic, Google, and DeepSeek, user authentication, and analytics.

## Setting up a project without built-in hosting

When you create a project, the default configuration includes hosting, a database, authentication, and analytics. If you plan to host your application elsewhere, you can provision only the services you need during initialization:

```bash
vibiz init "Acme Backend" --resources auth,ai
```

Choosing `auth` automatically sets up the Postgres database that backs user accounts and sessions. If you only want a single service, such as transactional email or analytics, request just that resource:

```bash
vibiz init "Acme Jobs" --resources email
```

For applications that need payments, file storage, social data, or web scraping, you can start with `--resources none`:

```bash
vibiz init "Acme Scraper" --resources none
```

These unbundled services require no background provisioning and are ready to call immediately. You can check the state of your project and its resources at any time:

```bash
vibiz status
```

To see how this fits alongside standalone projects, read [the cheapest way to host a website and database for a side project](https://thelastapi.dev/blog/cheapest-hosting-database-side-project) or consult the [Quickstart](https://thelastapi.dev/docs/quickstart) guide.

## Supplying the environment to your host

When you deploy to an external platform, container, or server, your application needs credentials to talk to the backend services. thelastapi provides a unified key called `VIBIZ_APP_KEY`. This one secret unlocks access to the database, sign-in endpoints, AI models, and file storage.

### 1. Retrieve the app key
Get your app key with the CLI:

```bash
vibiz app-key
```

This prints a secure link to copy the key. The secret itself is never written directly to the terminal output to avoid accidental logging in shared terminal sessions.

### 2. Run commands or build containers with the key
In a Dockerfile, automated script, or CI pipeline, set `VIBIZ_APP_KEY` in the environment. You can run your application commands directly through the CLI wrapper:

```bash
vibiz run -- node server.js
```

`vibiz run` reads `VIBIZ_APP_KEY` from the environment and injects all necessary service connection details into the child process. If your deployment tool needs an environment file at build time, pull the variables formatted for your setup:

```bash
# Export as a .env file
vibiz env pull --format dotenv -o .env.production

# Export as JSON or Docker-formatted lines
vibiz env pull --format docker -o docker.env
```

If you are deploying from automated workflows, see our guide on how to [deploy from CI with one command and one key](https://thelastapi.dev/blog/deploy-from-ci).

### 3. Direct production exports for owners
If you prefer not to use `VIBIZ_APP_KEY` at runtime, the account owner can print or write the raw production variables directly:

```bash
vibiz env --write .env.production
```

This command requires a full-access key. Limited keys (like those assigned to coding agents or CI runners) are restricted from printing raw production credentials and default to local development environments via `vibiz dev`.

## Connecting your domain for an external app

When running your app on an external server, you still need sign-in callbacks and analytics to accept your domain. Add your domain using the `--elsewhere` flag:

```bash
vibiz domains add app.example.com --elsewhere
```

This tells the platform that hosting is external (`hosting: "elsewhere"`). You will not receive instructions to point DNS records to our hosting servers, and the domain status becomes `external`. Analytics and session replay accept incoming events from the domain right away.

```bash
vibiz domains
```

To use user authentication on an externally hosted domain, sign-in trust must be confirmed:
1. If you add the domain via a full-access account key, it is trusted immediately.
2. If an AI agent or a limited key adds it, the command outputs a `trust_record` TXT entry (for example, `_vibiz.app.example.com` with a value of `vibiz-verify=...`). Add that record where your DNS is managed, then run:

```bash
vibiz domains verify app.example.com
```

Owners can also verify trust with a single click in the console under **Domains ▸ Trust for sign-in**.

### Using a domain bought through thelastapi

If you purchased your domain through the platform, DNS is already managed for you. You can route any subdomain or the apex domain to your external host in one command:

```bash
vibiz domains use sellshelf.app --project prj_123 --name app --elsewhere --points-to cname.yourhost.com
```

Our nameservers write the CNAME record automatically. To update where that address points later:

```bash
vibiz domains point app.sellshelf.app 192.0.2.1
```

For more details on managing registrar settings and records, visit the [Domains documentation](https://thelastapi.dev/docs/domains).

## Using backend services in code

Once your external host has `VIBIZ_APP_KEY` or the generated environment variables, connect to your resources using standard libraries or the `@vibiz/app` package.

### Serverless Postgres
The database connection string is provided as standard Postgres URL credentials. You can connect using any standard ORM or driver:

```ts
import { Pool } from 'pg';

const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
});

const result = await pool.query('SELECT NOW()');
console.log(result.rows[0]);
```

### Unified AI Gateway
The AI gateway operates over an OpenAI-compatible endpoint. Point the official OpenAI SDK to `VIBIZ_AI_BASE_URL` using `VIBIZ_AI_API_KEY` (or `OPENAI_BASE_URL` and `OPENAI_API_KEY`, which are aliased automatically):

```ts
import OpenAI from 'openai';

const openai = new OpenAI({
  baseURL: process.env.VIBIZ_AI_BASE_URL,
  apiKey: process.env.VIBIZ_AI_API_KEY,
});

const response = await openai.chat.completions.create({
  model: 'vibiz/fast',
  messages: [{ role: 'user', content: 'What is the server status?' }],
});

console.log(response.choices[0]?.message.content);
```

You can target unified models (`vibiz/fast`, `vibiz/smart`, `vibiz/pro`) or named lab models across OpenAI, Anthropic, Google, and DeepSeek without changing your code structure.

### The unified SDK
If you prefer not to manage individual service environment names, install `@vibiz/app`. It reads `VIBIZ_APP_KEY` directly:

```ts
import { vibiz } from '@vibiz/app';
import OpenAI from 'openai';

// Automatically connects using VIBIZ_APP_KEY
const openai = new OpenAI(vibiz.ai);
```

## Monitoring external applications and exporting data

Hosting off-platform does not mean losing visibility. Mission Control monitors your application's external endpoints, database health, traffic, and spend automatically.

Run health checks across all your projects from the terminal:

```bash
vibiz health
```

This scans your external domain, tests response codes, tracks error spikes, and monitors AI budget consumption. For full details on automated checks, review [Mission Control and health checks](https://thelastapi.dev/docs/mission-control).

| Check | What it monitors on external hosts | Failure condition |
| --- | --- | --- |
| Site up | Resolves your external domain over HTTPS | Answers 5xx, invalid SSL, or times out after 10 s |
| Resources | Database, auth, and email provisioning state | A resource is marked failed with an error |
| Errors | Session replay and frontend JavaScript errors | 10+ sessions with JS errors in 24 h (3x normal volume) |
| Limits | Project spend across AI and daily quotas | A project daily cap or budget ceiling is reached |

If you ever decide to move your entire stack away, the platform enforces no lock-in. You can download your database schema, row contents, and configuration using the [Export documentation](https://thelastapi.dev/docs/export) guidelines:

```bash
vibiz export --db --csv
```

This generates a compressed SQL dump (`<slug>-production-database.sql.gz`) that can be loaded into any Postgres instance:

```bash
gunzip -c acme-production-database.sql.gz | psql "$NEW_DATABASE_URL"
```

## Next steps

You can keep your compute layer anywhere while retaining a single control plane for databases, auth, AI routing, and billing. To learn more about full-stack deployment options, visit our [Hosting documentation](https://thelastapi.dev/docs/hosting). When you are ready to expand your application, browse our guides or create your account at [thelastapi.dev/start](https://thelastapi.dev/start).

## Frequently asked questions

### Do I have to use thelastapi hosting to use the database and AI gateway?

No. You can initialize a project with `--resources auth,ai` or `--resources none`, host your frontend or API server on any infrastructure, and connect via `VIBIZ_APP_KEY`.

### What DNS settings should I use if my site is hosted on another platform?

Add the domain to your project using `vibiz domains add yourdomain.com --elsewhere`. This marks the domain as external, so our hosting servers do not expect DNS routing records while sign-in and analytics still recognize your domain.

### Can an AI agent read my production database credentials for an external deployment?

No. AI agents operate using Limited keys by default, which cannot read production database secrets or output raw production environment variables. Only an account owner using a full-access key can run `vibiz env` or export production database snapshots.

---

Published 2026-11-15 · https://thelastapi.dev/blog/run-app-on-another-host-one-key
