#1648·postiz-app

Native Google Gemini (AI Studio) & Vertex AI support for text/agent features

Author: lupuleticCreated Jun 28, 2026Updated Sep 26, 2026
Labelsstale

Feature description

Add first-class support for Google Gemini as the LLM behind Postiz's text / agent features, in two flavours:

  1. Google AI Studio — Gemini via the generativelanguage.googleapis.com OpenAI-compatible endpoint, authenticated with a static GEMINI_API_KEY.
  2. Vertex AI — Gemini via the Vertex …-aiplatform.googleapis.com/.../endpoints/openapi OpenAI-compatible endpoint, authenticated with Application Default Credentials (ADC) / a GCP service account — i.e. no static API key. The bearer token is a short-lived OAuth token minted by google-auth-library (already a dependency of this repo).

Provider is chosen by env, defaulting to today's OpenAI behaviour so nothing changes for existing installs:

AI_TEXT_PROVIDER=openai|google|vertex   # default: openai
AI_TEXT_MODEL=gemini-2.5-flash          # used in google / vertex modes
GEMINI_API_KEY=...                      # google (AI Studio) mode
VERTEX_PROJECT=...                      # vertex mode (or GOOGLE_CLOUD_PROJECT)
VERTEX_LOCATION=europe-west1            # vertex mode (default: global)

This covers the text / agent path only. Image generation deliberately stays on OpenAI (OPENAI_API_KEY), because Gemini has no DALL·E-compatible endpoint the current DallEAPIWrapper / image calls can target.

Why is this feature needed?

  • There's repeated demand for non-OpenAI / self-host-friendly LLM options (#1074 has lots of , plus the older #592, #498, #445, #779, #192).
  • The Vertex AI case is not solved by a generic OPENAI_BASE_URL setting: Vertex uses keyless, IAM-based OAuth (ADC) instead of a static key, so it needs a per-request bearer token. This is a natural fit for anyone already self-hosting Postiz on GCP, who can use their existing Vertex credits / service account rather than buying separate OpenAI quota.
  • Issue #256 was previously closed as "not possible at the moment with CopilotKit" — that no longer holds. CopilotKit's OpenAIAdapter accepts an injected openai client + model, so the chat agent can target any OpenAI-compatible endpoint.

✌️ How do you aim to achieve this?

Reuse the OpenAI SDKs the project already depends on (openai, @langchain/openai's ChatOpenAI, @ai-sdk/openai, and CopilotKit's OpenAIAdapter) and point them at the Gemini OpenAI-compatible endpoints — no SDK swap and no new dependencies (only openai + google-auth-library, both already in package.json).

A single small helper centralises base URL / key / model and, for Vertex, a token-injecting fetch; the existing call sites just spread its config:

  • new ChatOpenAI({ ...textFields('gpt-4.1'), temperature }) — agent graph, autopost
  • new OpenAIAdapter({ openai: <client>, model }) — copilot controller (this is what unblocks #256)
  • createOpenAI(<config>).chat(model) — Mastra tool loader

With no env set, behaviour is byte-identical to today's OpenAI path, so it's fully backwards compatible.

I already have this implemented and tested end-to-end on a self-hosted instance (chat agent, autopost generation, and the agent graph all running on Gemini via Vertex AI with ADC), and am preparing a PR.

️ Additional Information / related work

  • Related open issue: #1074 (generic custom OpenAI base URL & model). This Gemini/Vertex request complements it — the Vertex ADC path is the piece a plain base-URL env can't cover.
  • Related PRs (all the generic OPENAI_BASE_URL approach): #1075 (open), #1167 (closed), #1449 (closed — note this one was auto-closed by a spam bot, not on merit).
  • Previously closed as not-possible: #256.

I checked and there's no existing Gemini- or Vertex-specific issue (only the generic base-URL ones linked above).

Willing to submit a PR: yes — implementation is ready and tested.