api

package
v7.0.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package api exposes helpers for embedding CLIProxyAPI.

It wraps internal management handler types and helpers so external projects can integrate management endpoints without importing internal packages.

Package api exposes server option helpers for embedding CLIProxyAPI.

It wraps internal server option types so external projects can configure the embedded HTTP server without importing internal packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompleteOAuthSession

func CompleteOAuthSession(state string)

CompleteOAuthSession marks a single OAuth session as completed.

func CompleteOAuthSessionsByProvider

func CompleteOAuthSessionsByProvider(provider string) int

CompleteOAuthSessionsByProvider removes all pending OAuth sessions for a provider.

func GetOAuthSession

func GetOAuthSession(state string) (provider string, status string, ok bool)

GetOAuthSession returns the current OAuth session state.

func IsOAuthSessionPending

func IsOAuthSessionPending(state, provider string) bool

IsOAuthSessionPending reports whether a provider/state pair is still pending.

func NormalizeOAuthProvider

func NormalizeOAuthProvider(provider string) (string, error)

NormalizeOAuthProvider normalizes a provider name to its canonical form.

func PopulateAuthContext

func PopulateAuthContext(ctx context.Context, c *gin.Context) context.Context

PopulateAuthContext copies auth metadata from a Gin context into a request context.

func RegisterOAuthSession

func RegisterOAuthSession(state, provider string)

RegisterOAuthSession records a pending OAuth callback state.

func SetOAuthSessionError

func SetOAuthSessionError(state, message string)

SetOAuthSessionError stores an OAuth session error message.

func ValidateOAuthState

func ValidateOAuthState(state string) error

ValidateOAuthState validates an OAuth state token.

func WriteConfig

func WriteConfig(path string, data []byte) error

WriteConfig persists management configuration to disk.

func WriteOAuthCallbackFile

func WriteOAuthCallbackFile(authDir, provider, state, code, errorMessage string) (string, error)

WriteOAuthCallbackFile writes an OAuth callback payload to disk.

func WriteOAuthCallbackFileForPendingSession

func WriteOAuthCallbackFileForPendingSession(authDir, provider, state, code, errorMessage string) (string, error)

WriteOAuthCallbackFileForPendingSession writes an OAuth callback payload for a pending session.

Types

type Handler

type Handler = internalmanagement.Handler

Handler re-exports the management handler used by the internal HTTP API.

func NewHandler

func NewHandler(cfg *config.Config, configFilePath string, manager *coreauth.Manager) *Handler

NewHandler creates a management handler for SDK consumers.

func NewHandlerWithoutConfigFilePath

func NewHandlerWithoutConfigFilePath(cfg *config.Config, manager *coreauth.Manager) *Handler

NewHandlerWithoutConfigFilePath creates a management handler that skips config file persistence.

type ManagementTokenRequester

type ManagementTokenRequester interface {
	RequestAnthropicToken(*gin.Context)
	RequestGeminiCLIToken(*gin.Context)
	RequestCodexToken(*gin.Context)
	RequestAntigravityToken(*gin.Context)
	RequestKimiToken(*gin.Context)
	GetAuthStatus(c *gin.Context)
	PostOAuthCallback(c *gin.Context)
}

ManagementTokenRequester exposes a limited subset of management endpoints for requesting tokens.

func NewManagementTokenRequester

func NewManagementTokenRequester(cfg *config.Config, manager *coreauth.Manager) ManagementTokenRequester

NewManagementTokenRequester creates a limited management handler exposing only token request endpoints.

type ServerOption

type ServerOption = internalapi.ServerOption

ServerOption customises HTTP server construction.

func WithEngineConfigurator

func WithEngineConfigurator(fn func(*gin.Engine)) ServerOption

WithEngineConfigurator allows callers to mutate the Gin engine prior to middleware setup.

func WithKeepAliveEndpoint

func WithKeepAliveEndpoint(timeout time.Duration, onTimeout func()) ServerOption

WithKeepAliveEndpoint enables a keep-alive endpoint with the provided timeout and callback.

func WithLocalManagementPassword

func WithLocalManagementPassword(password string) ServerOption

WithLocalManagementPassword stores a runtime-only management password accepted for localhost requests.

func WithMiddleware

func WithMiddleware(mw ...gin.HandlerFunc) ServerOption

WithMiddleware appends additional Gin middleware during server construction.

func WithRequestLoggerFactory

func WithRequestLoggerFactory(factory func(*config.Config, string) logging.RequestLogger) ServerOption

WithRequestLoggerFactory customises request logger creation.

func WithRouterConfigurator

func WithRouterConfigurator(fn func(*gin.Engine, *handlers.BaseAPIHandler, *config.Config)) ServerOption

WithRouterConfigurator appends a callback after default routes are registered.

Directories

Path Synopsis
Package handlers provides core API handler functionality for the CLI Proxy API server.
Package handlers provides core API handler functionality for the CLI Proxy API server.
claude
Package claude provides HTTP handlers for Claude API code-related functionality.
Package claude provides HTTP handlers for Claude API code-related functionality.
gemini
Package gemini provides HTTP handlers for Gemini CLI API functionality.
Package gemini provides HTTP handlers for Gemini CLI API functionality.
openai
Package openai provides HTTP handlers for OpenAI API endpoints.
Package openai provides HTTP handlers for OpenAI API endpoints.

Jump to

Keyboard shortcuts

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