Skip to content

Neon.AI Gateway reference

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.

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 },
});

Source: src/Neon/LanguageModel.ts Kind: 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.

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" })));

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.

const ai = yield* Neon.QueryAIGateway(gateway);
// Inside the request handler:
const baseURL = yield* ai.chatBaseUrl;
const apiKey = yield* ai.token;
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.