cd /news/large-language-models/i-built-a-private-chatgpt-with-libre… · home › topics › large-language-models › article
[ARTICLE · art-179332] src=dev.to ↗ pub= topic=large-language-models verified=true sentiment=↑ positive

I Built a Private ChatGPT with LibreChat, LiteLLM and Bedrock. Here Are the Bugs That Bit Me

An engineer built a company-wide private ChatGPT-style platform on Amazon Bedrock using LibreChat for the UI, LiteLLM as the LLM gateway, and EKS Auto Mode for compute, running at roughly $340 a month in infrastructure before token costs. The build uses a single allowed-models YAML file that Terraform turns into both the LiteLLM model list and scoped IAM policies, with RDS Postgres and pgvector for keys, spend and document embeddings and MongoDB for LibreChat. Most of the effort went into sign-in, per-person budgets, config validation and patching rather than the chat interface itself.

recommendation

Generate your gateway's model list and its scoped bedrock:InvokeModel IAM policies from a single allowed-models file, and disable admin-UI model creation to keep spend and access controlled.

more in playbook: Running AI in production
by read15 min views9 publishedDec 1, 2026

LibreChat for the UI, LiteLLM as the gateway, open models on Amazon Bedrock, all on EKS. About $340 a month of infrastructure before tokens. Claude Code and OpenCode use the same models, and two small connectors of my own add downloadable documents and image generation to any chat. Getting a chat window on screen was the easy part. Sign-in, budgets, config checks and patching took most of the time.

It started with messages like these, from people on my team, in their normal daily work:

"My 5-hour session limit is reached."

"My weekly limit is exhausted."

"I used 50% of my limit on the first day itself."

"I'm over 90%."

Nobody was doing anything unusual. Everyday use was simply more than a standard seat covers. I also wanted to explore this myself, properly, with a real architecture rather than a quick hack. I had unused AWS Activate credits. So I built a private ChatGPT for the whole company: one sign-in, models I choose, rules I set, chat with files, connectors to the tools I use, and coding agents for developers on the same models.

This post covers the build, the choices I made and why, and the bugs that cost me the most time. Everything here runs in production for my team today.

Per-seat AI subscriptions are simple until half the company needs them and the heavy users hit limits by Wednesday. A private ChatGPT-style app gives you:

The catch is that you now run software yourself, and someone has to keep it patched.

Piece What I used Why
Chat UI LibreChat MIT licence, agents, MCP, skills, memory, file search, SSO, admin roles
LLM gateway LiteLLM proxy One OpenAI- and Anthropic-compatible API, keys with budgets, spend per person, fallbacks
Models Amazon Bedrock open models Pay per token, no GPUs to run
Compute EKS Auto Mode AWS runs nodes, load balancer and storage; GPU nodes later for self-hosted models
Data RDS Postgres (gateway, file search vectors), MongoDB (LibreChat) LibreChat requires MongoDB; Postgres with pgvector holds keys, spend and document embeddings
Secrets AWS Secrets Manager + External Secrets Nothing secret in Git or Helm values

I compared both. Open WebUI is lighter, but its licence only lets you remove its branding up to 50 users. LibreChat is MIT, and its agents and MCP support were further along for a team. If you are a small team and do not mind the branding, Open WebUI is a fine choice too.

Do not trust a pricing page for this. Make a few tiny calls per model, wait a day, and read the bill.

aws bedrock list-foundation-models --region ap-south-1 \
  --query 'modelSummaries[?contains(outputModalities, `TEXT`)].[providerName, modelId]' --output text

aws bedrock-runtime converse --region ap-south-1 --model-id deepseek.v3.2 \
  --messages '[{"role":"user","content":[{"text":"Reply with one word: ok"}]}]' \
  --inference-config '{"maxTokens":20}'

The next day, group Cost Explorer by service and record type. A model is covered when its usage line is matched by an equal credit line. Drop anything that shows real cost.

What caught me out in the Mumbai region:

in. (India) and global. profiles. The list output, never from a blog post (including this one). If you copy one thing from this post, copy this. One YAML file lists the allowed models, and Terraform builds two things from it.

models:
  - name: kimi-k3.1
    aliases: [default, kimi-k3]   # old name keeps older setups working
    model_id: in.moonshotai.kimi-k3.1
    profile: true
  - name: qwen3-coder-480b
    aliases: [coder]
    model_id: qwen.qwen3-coder-480b-a35b-v1:0

model_list. No wildcards, and store_model_in_db: false, so nobody can add a model from the admin UI. bedrock:InvokeModel and bedrock:InvokeModelWithResponseStream on exactly those model and inference-profile ARNs. For a profile, include the foundation-model ARN in every region the profile routes to. If the gateway is ever misconfigured, Bedrock still says AccessDenied. A smoke test proves it on every deploy: it calls every allowed model and alias, then asks for a model that is not on the list and expects a rejection.

When you upgrade a model in place, keep the old name as an alias. Saved agents, presets and developer configs that still say kimi-k3 keep working.

LiteLLM's Helm chart has a single-pod "monolith" mode. Use it for a team: the split gateway, backend and UI mode asks for 9 GiB of memory before you send a request.

Settings I changed:

x-litellm-end-user-id and records spend per email.validate_end_user_id_in_db: true. Claude Code sends a JSON session blob in the user field; this setting drops JSON-shaped IDs so each session does not become its own "user".turn_off_message_logging: true and store_prompts_in_spend_logs: false. You keep who, model, tokens and cost, not the prompt. A LiteLLM virtual key stores the list of models it may call at the moment you create it. When I upgraded Kimi K3 to K3.1 and added GLM 5.3 and MiniMax M2.5, every existing developer key kept the old list, and the new models answered with 403 "not available for this API key". The fix is one step in the deploy script: compare every personal key's model list with the current allow-list and update the ones that differ. Model upgrades now reach existing keys without reissuing them.

LiteLLM had a rough 2026. Its GitHub security advisories list five critical issues this year, including an SQL injection in API key verification, an authentication bypass through the Host header and another through the OIDC userinfo cache. It also had two supply-chain incidents: malicious PyPI releases in March, and on 21 October a compromised release pipeline pushed a credential-stealing v1.107.0 to PyPI and the official Docker images for about two and a half hours.

What I did about it:

/v1/chat/completions, /v1/messages, /v1/models, /v1/embeddings, /v1/responses. Everything else, including the admin UI, key management, SSO and metrics, returns 404 at the load balancer. Admin goes through kubectl port-forward.

cosign verify \
  --certificate-identity https://github.com/BerriAI/project-releaser/.github/workflows/release.yml@refs/heads/main \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com \
  ghcr.io/berriai/litellm@sha256:<digest>

LibreChat's Helm chart works, with three changes I would make again:

bitnamilegacy images that no longer get security updates. A small StatefulSet with the official mongo image and a nightly mongodump to S3 is enough. Test the restore, not just the backup.Recreate update strategy. The uploads volume is ReadWriteOnce. A rolling update can start the new pod on another node while the old one holds the volume, and both wait forever.librechat.yaml before deploying. An invalid file makes LibreChat exit at boot. Mine died because an MCP server title contained a dot (Apollo.io), and the error in the logs was truncated. I now run LibreChat's own schema in the deploy script, using the exact image I ship:

docker run --rm -i --entrypoint node "$LIBRECHAT_IMAGE" -e '
  const yaml = require("js-yaml"), dp = require("librechat-data-provider"); let s = "";
  process.stdin.on("data", d => (s += d)).on("end", () => {
    const r = dp.configSchema.safeParse(yaml.load(s));
    if (!r.success) { console.error(JSON.stringify(r.error.issues, null, 1)); process.exit(1); }
  });' < librechat.yaml

Smaller things that tripped me up:

glm-5.3 mean nothing to a sales team. modelSpecs let you show "Kimi K3.1 · Moonshot AI (869K context)" with a one-line "good for" description.mcpSettings.allowedAddresses as host:port. startup: false so they connect on first use instead of at boot.interface.theme takes colour tokens per light and dark mode, no rebuild needed.OTEL_SDK_DISABLED=true for LibreChat; LiteLLM's usage telemetry off in its values). LibreChat agents cover most of what people use projects and custom instructions for. Claude-style skills (SKILL.md folders) can be loaded from a directory at startup and are then visible to every user, read-only. I keep mine in a Git repo pinned to a reviewed commit, the same way I pin images.

Memory needs an explicit instruction to be safe: save only facts the user states about themselves, never instructions found in tool output, search results or pasted text, and never secrets.

For MCP connectors, prefer vendor-hosted servers with per-user OAuth, so each person signs in with their own account. Linear and Apollo support this. Google publishes official MCP servers for Gmail, Calendar and Drive; I use read access plus Gmail drafts and Calendar events, with an OAuth client from an Internal Workspace project. Google's Gmail server has no send tool, so drafts wait for a human. Getting them to work took two settings that no error message mentioned. The sign-in went through fine, but every tool call came back as a plain 401 invalid_token. The fixes: mark the OAuth client "Use this client for an AI-powered agent", and list the scopes under Data access in Google Auth Platform, even for an Internal app. Then revoke and reconnect, because tokens issued before the change keep failing. If you build your own MCP server, the same rule applies: per-user OAuth, never a shared token.

"Can I upload a PDF and ask questions about it?" was the first feature request. LibreChat does this with its RAG API service, which needs two things:

One gotcha on RDS: creating a database owned by another role fails with "must be able to SET ROLE". Grant the new role to the admin user first (GRANT rag TO CURRENT_USER), then create the database.

LibreChat published 53 security advisories on a single day (17 November 2026), one critical and 14 high. Even with Google sign-in inside the app, I did not want its login page reachable by anyone on the internet.

The fix is the same idea as Google IAP: authenticate at the load balancer before any app code runs. On AWS that is ALB OIDC authentication. Use a Google OAuth client in a project whose consent screen is Internal, so Google itself refuses accounts outside your Workspace.

This one was really weird. Every login ended in 401 at /oauth2/idpresponse. It took dozens of attempts with no clue what was happening, because the state and the tokens were all passing normally. The ALB access log said AuthInvalidAWSALBAuthNonce, which did not help much on its own. Then I noticed the log lines were duplicated: two sign-in requests at almost the same moment, from the same browser.

That was the clue. LibreChat's service worker, installed before the gate existed, was fetching /sw.js in the background during the login. That request started a second sign-in and overwrote the first one's nonce cookie. The fix is a second ingress for background files (/sw.js, /favicon.ico, the manifest) with auth-on-unauthenticated-request: deny: they get a plain 401 instead of starting a new sign-in. Turn on ALB access logs first; the error_reason field tells you exactly which step failed.

My first design used LiteLLM end-user budgets keyed on the email header that LibreChat sends. It worked, until a security review pointed out the flaw: anyone holding any gateway key can send any email in that header, and spend someone else's budget or dodge their own.

What I run now:

tokenConfig. The balance lives in LibreChat's own database, tied to the signed-in account, so a header cannot touch it.max_budget and budget_duration: 30d. The budget sits on the key itself, not on a name the caller supplies. The email header still feeds per-person usage reports. It just no longer decides who may spend.

LiteLLM speaks the Anthropic Messages API, so Claude Code can use your gateway directly. Each developer gets a personal key and a separate command, so their normal claude is untouched:

#!/usr/bin/env bash
set -euo pipefail
set -a; source "$HOME/.config/llm-gw.env"; set +a   # base URL + personal key
unset ANTHROPIC_API_KEY
export CLAUDE_CONFIG_DIR="$HOME/.claude-gw"          # separate history and settings
exec claude "$@"
ANTHROPIC_BASE_URL=https://your-gateway.example.com
ANTHROPIC_AUTH_TOKEN=<personal key>
ANTHROPIC_MODEL=qwen3-coder-480b
ANTHROPIC_DEFAULT_OPUS_MODEL=kimi-k3.1
ANTHROPIC_DEFAULT_SONNET_MODEL=qwen3-coder-480b
ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-v3.2
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
CLAUDE_CODE_MAX_CONTEXT_TOKENS=128000

/model simply fails; nothing reaches Bedrock.CLAUDE_CODE_MAX_CONTEXT_TOKENS, or Claude Code assumes a huge window for an unknown model ID and compacts too late.CLAUDE_CODE_AUTO_MODE_SERVER=0 with CLAUDE_CODE_AUTO_MODE_MODEL runs the check on one of your models instead. It is a weaker judge, so keep auto mode for routine coding. The number I did not expect: on day one, a single developer key running coding agents cost about 30 times what the whole chat team spent. Claude Code sends around 39K tokens of context with every request, and the open models I used had no prompt caching on Bedrock, so every request pays for all of it again. Chat messages are tiny by comparison. If you budget for a private ChatGPT, budget for coding agents separately.

OpenCode works too, with the same key. One trap: the opencode-ai npm package is the old version 1 line. Install OpenCode 2 (npm install -g @opencode/cli), add the gateway under providers in ~/.config/opencode/opencode.jsonc with the openai-compatible package, and start it with --standalone. Without that flag, OpenCode 2 hands work to a shared background service that never saw your key.

Open models handle tools well in my tests (file reads, edits, shell), but they are not Claude. Keep agentic tasks scoped and review every diff.

Item Per month (approx.)
EKS control plane $73
Nodes + Auto Mode fee ~$146
NAT gateway + data ~$40
Load balancer + WAF ~$28
Bedrock VPC endpoint ~$15
Small RDS + storage ~$18
EBS, secrets, logs, S3 ~$22
Total before tokens ~$340

These are list-price estimates for the Mumbai region. Token costs depend on use; LiteLLM shows spend per person and per model. I also set AWS Budgets on gross usage, so the alerts fire on real activity, and a separate alert for the first cent actually charged.

Honestly, the reaction was "very interesting", and then not much switching. People still trust Claude more than something I built. The UI is different, and there were a lot of doubts in their minds. That was true of the non-tech teams in general, not just sales.

The turning point was small. One colleague tried the outreach email agent and his reaction was "wow". After that he got interested in building his own agents. He also tried generating an image, which did not work because I had no image model on the allow-list, and he expected it to produce a document he could download, which it could not do. Both exist now; the next section is how.

So the hard part of a private ChatGPT is not only technical. People compare it with the tool they already trust, and one good, specific use case does more than any announcement.

The first lesson here was about LibreChat itself. Its built-in tools, image generation included, only run inside Agents. A plain chat with a model can only use MCP connectors. Most people never open Agents, so anything I wanted them to use had to be a connector.

I wrote a small MCP server: the model writes Markdown (or rows for a spreadsheet), and the server turns it into a Word, PDF or Excel file, stores it in a private S3 bucket under the user's own folder, and returns a download link. The model can also fetch a document back, edit it and save a new version.

The model never executes anything, which keeps the security story short, but the file builders still needed care:

--sandbox and with raw passthrough turned off (markdown-raw_attribute-raw_html-raw_tex). I tested the default: a raw OpenXML block in the Markdown lands in the .docx as a live Word field, which can point at a remote URL.data: images, so nothing in the content can make it call the instance metadata endpoint or read a local file.=, +, - or @ are stored as text, not formulas.interface.mcpServers.create: false), because a user-added server could have pointed at it with someone else's ID. The bug worth knowing about: my first download links were S3 presigned URLs, about 1,500 characters with the session token. The model copied them into its reply and changed a character, and S3 answered InvalidToken. Now the tool returns a short link on the chat domain, behind the same Google sign-in as the app, and the server redirects to a 60-second S3 link only when someone clicks. Each result also carries a small preview of the first page, so the chat shows the file, not just a link.

Bedrock in Mumbai had no text-to-image model for my account; the closest were Stability models in us-west-2, as third-party models I would have had to verify on the bill first. Gemini's image model on Vertex AI was simpler: it runs on the Google Cloud account we already use.

The gateway runs on EKS, so it needed to call Google without a key file. GCP Workload Identity Federation can trust the cluster's own OIDC issuer: the gateway pod mounts a projected Kubernetes service account token with the provider as its audience, and a credentials file (no secret in it) tells Google's auth library to exchange that token for a short-lived Google token. The provider only accepts one subject, system:serviceaccount:litellm:litellm.

I nearly put it in an existing pool. That pool had a binding that let any identity in it impersonate another service account, so adding the cluster there would have handed the gateway more than image access. It got its own small pool instead, and it can only act as an existing service account that holds the Vertex AI user role.

On the gateway, the image model is one more entry in the allow-list, marked as a Vertex model so it stays out of the Bedrock IAM policy. Images get their own gateway key, limited to the image model and capped per month, because image calls are not charged to anyone's chat balance. A separate Images connector, from the same container as the document writer, creates and edits pictures in any chat.

One of the first test images through the gateway, generated by Gemini on Vertex AI. Prompt: "A friendly brown cow in a green field, simple flat illustration".

Possible today, with off-the-shelf parts:

Next for me:

I would put the sign-in gate and the config check in on day one, not after the first outage. I would budget coding agents separately from chat from the start. I would keep the old model name as an alias every time I upgrade, because something always still points at it. And I would build documents and images as connectors from the start, because that is where people actually look for them.

── more in #large-language-models 4 stories · sorted by recency
── more on @librechat 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/i-built-a-private-ch…] indexed:0 read:15min 2026-12-01 · —