Neon.AI Gateway reference
AIGateway
Section titled “AIGateway”Source:
src/Neon/AIGateway.ts
Discover a branch AI Gateway endpoint without inventing gateway CRUD. The construct never purchases credits or changes the account plan. Native Neon Functions use injected credentials; QueryAIGatewayHttp owns a scoped service credential when none is supplied. Model access and credits remain separate.
AIGateway: Connect an existing branch
Section titled “AIGateway: Connect an existing branch”const gateway = yield* Neon.AIGateway("AI", { branch });// In a Function init Effect:const ai = yield* Neon.QueryAIGateway(gateway);const model = ai.model({ model: "gpt-5-mini" });// Provide model to Effect AI generateText/generateObject/streamText in a handler.AIGateway: Use output references explicitly
Section titled “AIGateway: Use output references explicitly”const gateway = yield* Neon.AIGateway("AI", { branch: { projectId: project.projectId, branchId: branch.branchId },});makeLanguageModelLayer
Section titled “makeLanguageModelLayer”Source:
src/Neon/LanguageModel.tsKind: Layer · Provides:effect/unstable/ai/LanguageModel
Effect AI over Neon’s documented /v1/chat/completions route. Supports text,
image inputs, function tools, JSON-schema output and cancellable SSE streams.
Tool and structured-output support depends on the selected model. Responses-only
models (including Codex), native Anthropic thinking/cache controls, audio,
provider-executed tools and image generation are not supported by this adapter.
Use the bound client’s dialect URLs with a native SDK for those APIs.
makeLanguageModelLayer: Generate text
Section titled “makeLanguageModelLayer: Generate text”const ai = yield* Neon.QueryAIGateway(gateway);const model = ai.model({ model: "gpt-5-mini" });// Inside the Function or Worker request handler:const reply = yield* LanguageModel.generateText({ prompt: "Say hello." }).pipe( Effect.provide(model),);makeLanguageModelLayer: Generate structured output
Section titled “makeLanguageModelLayer: Generate structured output”const reply = yield* LanguageModel.generateObject({ prompt: "Return a short greeting.", schema: Schema.Struct({ greeting: Schema.String }),}).pipe(Effect.provide(ai.model({ model: "gpt-5-mini" })));QueryAIGateway
Section titled “QueryAIGateway”Source:
src/Neon/QueryAIGateway.ts
Obtain an Effect AI LanguageModel or SDK-compatible endpoint and credential effects; no model calls happen during deployment. QueryAIGatewayHttp uses the same-branch Function’s injected grant, otherwise a tracked branch credential. An explicit credential overrides injection. The injected grant remains available to the whole Function process; a binding is not a permission sandbox.
QueryAIGateway: Configure a model client
Section titled “QueryAIGateway: Configure a model client”const ai = yield* Neon.QueryAIGateway(gateway);// Inside the request handler:const baseURL = yield* ai.chatBaseUrl;const apiKey = yield* ai.token;QueryAIGateway: Use Effect AI
Section titled “QueryAIGateway: Use Effect AI”const ai = yield* Neon.QueryAIGateway(gateway);const model = ai.model({ model: "gpt-5-mini" });// Inside a Function or Worker handler:const reply = yield* LanguageModel.generateText({ prompt: "Say hello." }).pipe( Effect.provide(model),);model uses Chat Completions, including for Claude models. For Responses-only
models or native Anthropic features, use responsesBaseUrl or
anthropicBaseUrl with the corresponding SDK and the redacted token.