gemini

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package gemini provides Google Gemini API integration for the LLM gateway.

Index

Constants

This section is empty.

Variables

View Source
var Registration = providers.Registration{
	Type: "gemini",
	New:  New,
	Discovery: providers.DiscoveryConfig{
		DefaultBaseURL: defaultOpenAICompatibleBaseURL,

		CredentialFields: []providers.CredentialField{
			{Name: providers.CredentialFieldAPIKeys},
			{Name: providers.CredentialFieldBackend, Options: []string{geminiBackendAIStudio, geminiBackendVertex}},
			{Name: providers.CredentialFieldBaseURL, Advanced: true},
			{Name: providers.CredentialFieldAPIMode, Advanced: true, Options: []string{geminiAPIModeNative, geminiAPIModeOpenAICompatible}},
			{Name: providers.CredentialFieldAuthType, Advanced: true, Options: []string{geminiAuthTypeAPIKey, geminiAuthTypeGCPADC, geminiAuthTypeServiceKey}},
			{Name: providers.CredentialFieldVertexProject, Advanced: true},
			{Name: providers.CredentialFieldVertexLocation, Advanced: true},
			{Name: providers.CredentialFieldServiceAccountJSON, Advanced: true},
			{Name: providers.CredentialFieldServiceAccountFile, Advanced: true},
			{Name: providers.CredentialFieldServiceAccountJSONBase64, Advanced: true},
			{Name: providers.CredentialFieldGCPScope, Advanced: true},
		},
	},
}

Registration provides factory registration for the Gemini provider.

Functions

func New

New creates a new Gemini provider.

Types

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements the core.Provider interface for Google Gemini

func NewVertexWithHTTPClient

func NewVertexWithHTTPClient(providerCfg providers.ProviderConfig, opts providers.ProviderOptions, httpClient *http.Client) *Provider

NewVertexWithHTTPClient creates a Vertex-configured Gemini provider using an already-authenticated HTTP client. It is used by the vertex package so Vertex owns Google auth while reusing Gemini request/response translation.

func (*Provider) CancelBatch

func (p *Provider) CancelBatch(ctx context.Context, id string) (*core.BatchResponse, error)

CancelBatch cancels a native Gemini batch job.

func (*Provider) ChatCompletion

func (p *Provider) ChatCompletion(ctx context.Context, req *core.ChatRequest) (*core.ChatResponse, error)

ChatCompletion sends a chat completion request to Gemini

func (*Provider) CreateBatch

func (p *Provider) CreateBatch(ctx context.Context, req *core.BatchRequest) (*core.BatchResponse, error)

CreateBatch creates a native Gemini batch job through its OpenAI-compatible endpoint.

func (*Provider) CreateFile

func (p *Provider) CreateFile(ctx context.Context, req *core.FileCreateRequest) (*core.FileObject, error)

CreateFile uploads a file through Gemini's OpenAI-compatible /files API.

func (*Provider) CreateImage added in v0.1.81

CreateImage implements OpenAI-compatible image generation for Gemini. In native mode Imagen models are served through models/{model}:predict and Gemini image models (gemini-2.5-flash-image, ...) through generateContent with image response modalities. In OpenAI-compatible mode the request is forwarded to Gemini's /openai/images/generations endpoint unchanged.

func (*Provider) CreateImageEdit added in v0.1.81

func (p *Provider) CreateImageEdit(ctx context.Context, req *core.ImageEditRequest) (*core.ImageGenerationResponse, error)

CreateImageEdit implements OpenAI-compatible image edits for Gemini image models through the native generateContent API: uploaded images become inline_data parts ahead of the prompt text. Imagen models only generate, and the OpenAI-compatible surface has no edits endpoint, so both are rejected with a pointer to what works.

func (*Provider) DeleteFile

func (p *Provider) DeleteFile(ctx context.Context, id string) (*core.FileDeleteResponse, error)

DeleteFile deletes a file object through Gemini's OpenAI-compatible /files API.

func (*Provider) Embeddings

Embeddings sends an embeddings request to Gemini: the native batchEmbedContents API in native mode, or the OpenAI-compatible endpoint otherwise. The Vertex backend always uses the OpenAI-compatible surface — Vertex has no batchEmbedContents; its native prediction path is served by the dedicated vertex provider.

func (*Provider) GetBatch

func (p *Provider) GetBatch(ctx context.Context, id string) (*core.BatchResponse, error)

GetBatch retrieves a native Gemini batch job.

func (*Provider) GetBatchResults

func (p *Provider) GetBatchResults(ctx context.Context, id string) (*core.BatchResultsResponse, error)

GetBatchResults fetches Gemini batch results via the output file API.

func (*Provider) GetFile

func (p *Provider) GetFile(ctx context.Context, id string) (*core.FileObject, error)

GetFile retrieves one file object through Gemini's OpenAI-compatible /files API.

func (*Provider) GetFileContent

func (p *Provider) GetFileContent(ctx context.Context, id string) (*core.FileContentResponse, error)

GetFileContent fetches raw file bytes through Gemini's /files/{id}/content API.

func (*Provider) ListBatches

func (p *Provider) ListBatches(ctx context.Context, limit int, after string) (*core.BatchListResponse, error)

ListBatches lists native Gemini batch jobs.

func (*Provider) ListFiles

func (p *Provider) ListFiles(ctx context.Context, purpose string, limit int, after string) (*core.FileListResponse, error)

ListFiles lists files through Gemini's OpenAI-compatible /files API.

func (*Provider) ListModels

func (p *Provider) ListModels(ctx context.Context) (*core.ModelsResponse, error)

ListModels retrieves the list of available models from Gemini, following the native listing's page tokens so models past the first page of 50 are not dropped.

func (*Provider) Responses

Responses sends a Responses API request to Gemini (converted to chat format)

func (*Provider) SetBaseURL

func (p *Provider) SetBaseURL(url string)

SetBaseURL allows configuring a custom base URL for the provider

func (*Provider) SetModelsURL

func (p *Provider) SetModelsURL(url string)

SetModelsURL allows configuring a custom models API base URL. This is primarily useful for tests and local emulators.

func (*Provider) StreamChatCompletion

func (p *Provider) StreamChatCompletion(ctx context.Context, req *core.ChatRequest) (io.ReadCloser, error)

StreamChatCompletion returns a raw response body for streaming (caller must close)

func (*Provider) StreamResponses

func (p *Provider) StreamResponses(ctx context.Context, req *core.ResponsesRequest) (io.ReadCloser, error)

StreamResponses returns a raw response body for streaming Responses API (caller must close)

Jump to

Keyboard shortcuts

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