api

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(cfg *config.Config) gin.HandlerFunc

AuthMiddleware returns a Gin middleware handler that authenticates requests using API keys. If no API keys are configured, it allows all requests.

Types

type APIHandlers

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

APIHandlers contains the handlers for API endpoints. It holds a pool of clients to interact with the backend service.

func NewAPIHandlers

func NewAPIHandlers(cliClients []*client.Client, cfg *config.Config) *APIHandlers

NewAPIHandlers creates a new API handlers instance. It takes a slice of clients and a debug flag as input.

func (*APIHandlers) CLIHandler added in v1.8.2

func (h *APIHandlers) CLIHandler(c *gin.Context)

func (*APIHandlers) ChatCompletions

func (h *APIHandlers) ChatCompletions(c *gin.Context)

ChatCompletions handles the /v1/chat/completions endpoint. It determines whether the request is for a streaming or non-streaming response and calls the appropriate handler.

func (*APIHandlers) GeminiHandler added in v1.9.0

func (h *APIHandlers) GeminiHandler(c *gin.Context)

func (*APIHandlers) Models

func (h *APIHandlers) Models(c *gin.Context)

Models handles the /v1/models endpoint. It returns a hardcoded list of available AI models.

type ErrorDetail

type ErrorDetail struct {
	// A human-readable message providing more details about the error.
	Message string `json:"message"`
	// The type of error that occurred (e.g., "invalid_request_error").
	Type string `json:"type"`
	// A short code identifying the error, if applicable.
	Code string `json:"code,omitempty"`
}

ErrorDetail provides specific information about an error that occurred. It includes a human-readable message, an error type, and an optional error code.

type ErrorResponse

type ErrorResponse struct {
	Error ErrorDetail `json:"error"`
}

ErrorResponse represents a standard error response format for the API. It contains a single ErrorDetail field.

type Server

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

Server represents the main API server. It encapsulates the Gin engine, HTTP server, handlers, and configuration.

func NewServer

func NewServer(cfg *config.Config, cliClients []*client.Client) *Server

NewServer creates and initializes a new API server instance. It sets up the Gin engine, middleware, routes, and handlers.

func (*Server) Start

func (s *Server) Start() error

Start begins listening for and serving HTTP requests. It's a blocking call and will only return on an unrecoverable error.

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop gracefully shuts down the API server without interrupting any active connections.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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