> ## Documentation Index
> Fetch the complete documentation index at: https://greenteagentic.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Gateway

> How Green Teagentic talks to LLMs.

The **Teagentic AI Gateway** is a thin in-house wrapper around an OpenAI-compatible chat completions endpoint. It centralizes auth, JSON-mode enforcement, model defaults, and graceful fallback so every brew stage uses the same interface.

All LLM calls go through `src/lib/ai-gateway.server.ts`:

```ts theme={null}
import { chatJSON } from "@/lib/ai-gateway.server";

const result = await chatJSON<MyShape>([
  { role: "system", content: "..." },
  { role: "user", content: "..." },
], { model: "google/gemini-3-flash-preview" });
```

## Defaults

* **Endpoint:** `https://api.teagentic.ai/v1/chat/completions`
* **Model:** `google/gemini-3-flash-preview`
* **Response format:** forced to `json_object`

## Auth

The gateway is authenticated via the `X-Teagentic-Key` header, read from `process.env.TEAGENTIC_AI_KEY` at call time. Set this once in your hosting provider's secret store; it's never exposed to the browser.

## Fallbacks

If the key is missing or the call fails, `chatJSON` returns `null`. The brew pipeline catches this and uses `mockFallback()` to keep the UI demoable. This means **the app is always usable**, even without credentials — but outputs will be generic.

## Switching models

Supported models include the full Gemini and GPT families. Pass `{ model: "openai/gpt-5-mini" }` to `chatJSON` to override per-call.
