### Install @upstash/qstash Source: https://layerbase.com/docs/vqueue Install the @upstash/qstash package to use the qstash Client with VQueue. ```bash pnpm add @upstash/qstash ``` -------------------------------- ### Example source connection strings Source: https://layerbase.com/docs/cloud/migrate Shows the format for connection strings accepted by Layerbase for providers that do not use API keys. Includes PostgreSQL, MySQL, Redis, and MongoDB examples. ```plaintext postgresql://user:password@host:5432/dbname mysql://user:password@host:3306/dbname rediss://default:password@host:6379 mongodb+srv://user:password@cluster.example.mongodb.net/dbname ``` -------------------------------- ### Set environment variables and list databases Source: https://layerbase.com/docs A complete example showing how to export environment variables and perform a request to list databases. ```bash $ export LAYERBASE_API_URL=https://cloud.layerbase.dev $ export LAYERBASE_API_KEY=sk_xxxxxxxxxxxx $ curl $LAYERBASE_API_URL/v1/databases \ -H "Authorization: Bearer $LAYERBASE_API_KEY" ``` -------------------------------- ### Install Layerbase skill globally with --global flag Source: https://layerbase.com/docs/agents Use the --global flag to install the Layerbase skill once for every project, writing it to ~/.claude/skills/layerbase/SKILL.md. This is useful for agents that work across multiple repositories. ```bash npx layerbase agent init --global # writes ~/.claude/skills/layerbase/SKILL.md ``` -------------------------------- ### List databases via cURL Source: https://layerbase.com/docs An example of how to list databases on your account using the cURL command-line tool with an authorization header. ```bash # List databases on your account $ curl https://cloud.layerbase.dev/v1/databases \ -H "Authorization: Bearer $LAYERBASE_API_KEY" # Returns JSON { "databases": [ ... ] } ``` -------------------------------- ### Set up Better Auth with libSQL (auth.ts) Source: https://layerbase.com/docs/libsql-auth Install the Better Auth, libSQL client, and Kysely packages, then configure the Better Auth server with a libSQL dialect using LIBSQL_URL and LIBSQL_AUTH_TOKEN environment variables. The emailAndPassword option enables email and password authentication. ```bash pnpm add better-auth @libsql/client @libsql/kysely-libsql kysely ``` ```ts import { betterAuth } from 'better-auth' import { createClient } from '@libsql/client' import { LibsqlDialect } from '@libsql/kysely-libsql' export const auth = betterAuth({ database: { dialect: new LibsqlDialect({ client: createClient({ url: process.env.LIBSQL_URL!, authToken: process.env.LIBSQL_AUTH_TOKEN, }), }), type: 'sqlite', }, emailAndPassword: { enabled: true }, }) ``` -------------------------------- ### List databases with GET /v1/databases Source: https://layerbase.com/docs/api Lists databases you own or share via a team. The response includes limits, counts, and database entries with fields such as id, name, engine, version, status, host, port, connectionString, access, server/serverPool, and transient fields. ```bash curl $LAYERBASE_API_URL/v1/databases \ -H "Authorization: Bearer $LAYERBASE_API_KEY" ``` -------------------------------- ### GET /v1/databases/:id Source: https://layerbase.com/docs Gets a single database by its ID. Requires a personal API key in the Authorization header. ```APIDOC ## GET /v1/databases/:id ### Description Gets a single database by its ID. Requires a personal API key in the Authorization header. ### Method GET ### Endpoint /v1/databases/:id ### Authentication Bearer token (Authorization: Bearer sk_) ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the database to retrieve. ### Response #### Success Response (200) Returns the database details. #### Response Example { "id": "...", "connectionString": "postgresql://admin:••••@your-db.cloud.layerbase.dev/db?sslmode=require" } ``` -------------------------------- ### Create a database with POST /v1/databases Source: https://layerbase.com/docs/api Provisions a new database. Only engine is required; other parameters have defaults. Returns 201 with the new database, including connection details and status. Fast engines return running; slow-start engines return provisioning and require polling GET /v1/databases/:id until running. Common failures: 400, 403, 409, 429. ```bash curl -X POST $LAYERBASE_API_URL/v1/databases \ -H "Authorization: Bearer $LAYERBASE_API_KEY" \ -H "Content-Type: application/json" \ -d '{"engine": "postgresql", "name": "my-app"}' ``` -------------------------------- ### GET /health Source: https://layerbase.com/docs Health probe endpoint. Does not require authentication. ```APIDOC ## GET /health ### Description Health probe endpoint. Does not require authentication. ### Method GET ### Endpoint /health ### Authentication None ### Response #### Success Response (200) Returns a health status. #### Response Example { "status": "ok" } ``` -------------------------------- ### Install Layerbase skill into a project with npx layerbase agent init Source: https://layerbase.com/docs/agents Run this command in your project to fetch the latest Layerbase skill and write it to ./.claude/skills/layerbase/SKILL.md. It also prints an AGENTS.md snippet for other agents. The command fetches the always-current skill from layerbase.com/skill.md and falls back to the bundled copy when offline. ```bash npx layerbase agent init # writes ./.claude/skills/layerbase/SKILL.md # and prints an AGENTS.md snippet for other agents ``` -------------------------------- ### GET /v1/me response Source: https://layerbase.com/docs/api Response body for GET /v1/me. Shows the authenticated user's id, email, and plan, plus current programmatic-create usage with used count, monthly limit, and reset time. The limit is null when the plan is unmetered (Custom plan on own servers). ```json { "user": { "id": "...", "email": "you@example.com", "plan": "pro" }, "usage": { "programmaticCreates": { "used": 12, "limit": 500, "resetsAt": "2026-08-01T00:00:00.000Z" } } } ``` -------------------------------- ### Create Better Auth client and sign in/up Source: https://layerbase.com/docs/libsql-auth Create a Better Auth client and use it to sign up and sign in with email and password. The client SDK reads like Supabase's. ```ts import { createAuthClient } from 'better-auth/client' export const authClient = createAuthClient() await authClient.signUp.email({ email, password, name }) await authClient.signIn.email({ email, password }) ``` -------------------------------- ### GET /v1/engines Source: https://layerbase.com/docs Retrieves the public engine registry. This endpoint does not require authentication. ```APIDOC ## GET /v1/engines ### Description Retrieves the public engine registry. This endpoint does not require authentication. ### Method GET ### Endpoint /v1/engines ### Authentication None ### Response #### Success Response (200) Returns a list of available database engines. #### Response Example { "engines": [ ... ] } ``` -------------------------------- ### Base URL Source: https://layerbase.com/docs/api The base URL for all API requests. Stored in the $LAYERBASE_API_URL variable in examples. ```text https://cloud.layerbase.dev ``` -------------------------------- ### GET /v1/databases Source: https://layerbase.com/docs Lists databases on your account. Requires a personal API key in the Authorization header. ```APIDOC ## GET /v1/databases ### Description Lists databases on your account. Requires a personal API key in the Authorization header. ### Method GET ### Endpoint /v1/databases ### Authentication Bearer token (Authorization: Bearer sk_) ### Response #### Success Response (200) Returns a JSON object containing a list of databases. #### Response Example { "databases": [ ... ] } ``` -------------------------------- ### Connect with psql using client certificate and sslmode=verify-full Source: https://layerbase.com/docs/security/client-certificates Use psql with sslmode=verify-full and sslrootcert=system to verify the server against the OS trust store. Do not use ca.crt as sslrootcert; it will fail with 'certificate verify failed'. Requires libpq 16 or newer for sslrootcert=system. ```bash $ psql "sslmode=verify-full \ sslrootcert=system \ sslcert=client.crt \ sslkey=client.key \ host=your-db.cloud.layerbase.com port=5432 \ dbname=app user=app_user" ``` -------------------------------- ### GET /v1/api-keys Source: https://layerbase.com/docs Lists your personal API keys. Requires a personal API key in the Authorization header. ```APIDOC ## GET /v1/api-keys ### Description Lists your personal API keys. Requires a personal API key in the Authorization header. ### Method GET ### Endpoint /v1/api-keys ### Authentication Bearer token (Authorization: Bearer sk_) ### Response #### Success Response (200) Returns a list of API keys. #### Response Example { "apiKeys": [ ... ] } ``` -------------------------------- ### Generate and apply Better Auth schema with CLI commands for Drizzle, Prisma, and Kysely Source: https://layerbase.com/docs/auth Run the Better Auth CLI to generate the schema for your adapter, then apply it with your ORM's migration tool. Drizzle writes schema.ts and uses drizzle-kit push; Prisma writes prisma/schema.prisma and uses prisma migrate; Kysely writes schema.sql and can use the built-in migrate command. The CLI is published as @better-auth/cli, also invokable as npx auth@latest. ```bash # Drizzle: generate schema.ts, then push (or generate + run a migration) npx @better-auth/cli@latest generate npx drizzle-kit push # Prisma: generate into prisma/schema.prisma, then migrate npx @better-auth/cli@latest generate npx prisma migrate dev # Kysely or raw SQL: generate schema.sql, then apply it npx @better-auth/cli@latest generate npx @better-auth/cli@latest migrate # built-in Kysely adapter only ``` -------------------------------- ### GET /v1/databases Source: https://layerbase.com/docs/api Lists the databases you own plus any shared with you through a team. Returns limits, counts, and database entries. ```APIDOC ## GET /v1/databases ### Description Lists the databases you own plus any shared with you through a team. ### Method GET ### Endpoint /v1/databases ### Response #### Success Response (200) - **limits** (object) - Reports your branch allowances. - **counts** (object) - Splits primaries from branches. - **databases** (array) - Each entry includes: id, name, engine, version, status, host, port, connectionString, access (owner or member), server, serverPool (shared or dedicated), expiresAt, transient. #### Response Example { "limits": {}, "counts": {}, "databases": [] } ### Request Example ``` curl $LAYERBASE_API_URL/v1/databases \ -H "Authorization: Bearer $LAYERBASE_API_KEY" ``` ``` -------------------------------- ### Connect to MySQL/MariaDB with @planetscale/database Source: https://layerbase.com/docs/cloud/serverless-edge Use the PS URL, username, and password to create a connection and execute a query. ```javascript import { connect } from '@planetscale/database' const conn = connect({ host: 'YOUR_PS_URL'.replace('https://', ''), username: 'YOUR_PS_USERNAME', password: 'YOUR_PS_PASSWORD', }) const result = await conn.execute('SELECT * FROM users') ``` -------------------------------- ### Connect to MariaDB with mariadb CLI Source: https://layerbase.com/docs/cloud/connecting/mariadb Connect to a Layerbase MariaDB instance using the mariadb CLI with TLS enabled. Replace with the allocated TLS port shown in Quick Connect; there is no shared 3306 port. For strict certificate verification, add --ssl-verify-server-cert against the direct endpoint (pooler port toggle off). ```bash mariadb --ssl --host your-host.cloud.layerbase.dev --port --user layerbase --password app ``` -------------------------------- ### GET /v1/ip Source: https://layerbase.com/docs/security/ip-allowlisting Returns the public IP address that the request originates from. Useful for determining the current IP to add to an allowlist. ```APIDOC ## [GET] /v1/ip ### Description Returns the public IP address this request came from. ### Method GET ### Endpoint /v1/ip ### Authentication Requires `Authorization: Bearer sk_...` header with an account or database-scoped API key. ### Response #### Success Response (200) - **ip** (string) - The public IP address of the request. #### Response Example { "ip": "203.0.113.5" } ``` -------------------------------- ### Initialize libSQL client with tslibSQL Source: https://layerbase.com/docs/cloud/connecting/libsql Use the createClient function to connect to your libSQL database using the host URL and authentication token from the dashboard. ```typescript const db = createClient({ url: 'https://your-host.cloud.layerbase.dev', authToken: process.env.LIBSQL_AUTH_TOKEN }) ```