ai studio bridge - nself-org/cli GitHub Wiki
Start a secure Google AI Studio bridge via Cloudflare Tunnel.
Opens a local HTTP reverse proxy and exposes it to Google AI Studio through an ephemeral Cloudflare Tunnel (trycloudflare.com, no account required). Gemini can query your local Postgres schema and run GraphQL reads against your ɳSelf instance without any cloud deployment.
nself ai-studio bridge [flags]| Flag | Default | Description |
|---|---|---|
--port |
8890 |
Local proxy port |
--no-context |
false |
Disable X-Nself-Schema-Context header injection |
--dry-run |
false |
Print tunnel info without starting proxy |
--idle-timeout |
30 |
Auto-close tunnel after N minutes of inactivity |
--ip-allowlist |
`` | Comma-separated CIDRs to restrict tunnel access |
--region |
auto |
Cloudflare tunnel region |
| Variable | Description |
|---|---|
NSELF_AISTUDIO_PROXY_PORT |
Local proxy port (overridden by --port) |
NSELF_AISTUDIO_TUNNEL_REGION |
Cloudflare tunnel region |
NSELF_AISTUDIO_SCHEMA_CONTEXT |
Set to false to disable schema injection |
NSELF_AISTUDIO_AUTH_TOKEN |
Pre-shared auth token (auto-generated when unset) |
HASURA_GRAPHQL_ENDPOINT |
Hasura endpoint (default: http://localhost:8080) |
HASURA_GRAPHQL_ADMIN_SECRET |
Hasura admin secret |
-
cloudflaredis downloaded automatically to~/.nself/bin/cloudflaredif not present. - A local HTTP proxy starts on
--port(default 8890). - Cloudflare Tunnel connects the proxy to a
*.trycloudflare.comURL. - Every GraphQL request is forwarded to Hasura using the
ai_studio_readrole, mutations and DDL are blocked at the proxy layer. - The
X-Nself-Schema-Contextresponse header carries a base64-encoded JSON snapshot of your table structure so Gemini can understand your schema without a round-trip. - The tunnel auto-closes after the idle timeout (default 30 minutes).
- All requests require an
Authorization: Bearer <token>header. - The token is auto-generated (64-char hex) each session unless
NSELF_AISTUDIO_AUTH_TOKENis set. - Only read operations (
query) are allowed. Mutations are blocked with HTTP 403. - Use
--ip-allowlist 192.168.1.0/24to restrict access to specific CIDRs. - The Hasura role
ai_studio_readmust exist in your Hasura metadata (SELECT only).
# Start bridge with defaults
nself ai-studio bridge
# Disable schema header injection
nself ai-studio bridge --no-context
# Test what the bridge would do (no real tunnel)
nself ai-studio bridge --dry-run
# Restrict to local network only
nself ai-studio bridge --ip-allowlist 192.168.1.0/24
# Extend idle timeout to 60 minutes
nself ai-studio bridge --idle-timeout 60After starting the bridge:
- Copy the
AI Studio bridge ready: https://xxxx.trycloudflare.comURL. - In Google AI Studio, open Custom connector.
- Paste
https://xxxx.trycloudflare.com/v1/graphqlas the endpoint. - Add header:
Authorization: Bearer <token>(token is printed at startup). - Gemini will now have access to your local schema via
X-Nself-Schema-Context.