gemini

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package gemini is a reference backend emulator for the Google Gemini generateContent API. It serves POST …:generateContent and …:streamGenerateContent?alt=sse with JSON or SSE bodies compatible with google.golang.org/genai (Google AI / ML dev backend).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(cfg Config) http.Handler

NewHandler returns an http.Handler that emulates generateContent / streamGenerateContent for the official genai SDK (API key backend).

Types

type Config

type Config struct {
	// AllowMissingAPIKey, if true, skips the x-goog-api-key header check.
	AllowMissingAPIKey bool
	// OnAuthorizedCredential is invoked after local auth passes with the raw x-goog-api-key value.
	// Do not log this value.
	OnAuthorizedCredential func(secret string)
	// ForcedHTTPStatus, when 401 or 429, returns that status with provider-shaped JSON instead of success.
	ForcedHTTPStatus int
	// ForcedRetryAfter is sent as Retry-After when ForcedHTTPStatus is 429.
	ForcedRetryAfter string
	// ForcedErrorJSON overrides the forced-error JSON body; when empty a minimal default is used.
	ForcedErrorJSON string
	// OnRequestBody is invoked with the full request body after a successful route/auth
	// check and before the response is written.
	OnRequestBody func(body []byte)
	// NonStreamJSON overrides the JSON body for non-streaming responses. When empty, a
	// minimal completed candidate is returned.
	NonStreamJSON string
	// StreamSSE overrides the full SSE payload for streaming responses. When empty, a
	// minimal single data chunk is returned (double-newline terminated for the genai client).
	StreamSSE string
}

Config tunes the emulator handler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL