{"modulePath":"github.com/luispater/CLIProxyAPI","version":"v1.9.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package api\n\n## Functions\n\n```go\nfunc AuthMiddleware(cfg *config.Config) gin.HandlerFunc\n```\nAuthMiddleware returns a Gin middleware handler that authenticates requests using API keys. If no API keys are configured, it allows all requests.\n\n## Types\n\n```go\ntype APIHandlers struct {\n\t// contains filtered or unexported fields\n}\n```\nAPIHandlers contains the handlers for API endpoints. It holds a pool of clients to interact with the backend service.\n\n```go\nfunc NewAPIHandlers(cliClients []*client.Client, cfg *config.Config) *APIHandlers\n```\nNewAPIHandlers creates a new API handlers instance. It takes a slice of clients and a debug flag as input.\n\n```go\nfunc (h *APIHandlers) CLIHandler(c *gin.Context)\n```\n\n```go\nfunc (h *APIHandlers) ChatCompletions(c *gin.Context)\n```\nChatCompletions handles the /v1/chat/completions endpoint. It determines whether the request is for a streaming or non-streaming response and calls the appropriate handler.\n\n```go\nfunc (h *APIHandlers) GeminiHandler(c *gin.Context)\n```\n\n```go\nfunc (h *APIHandlers) Models(c *gin.Context)\n```\nModels handles the /v1/models endpoint. It returns a hardcoded list of available AI models.\n\n```go\ntype ErrorDetail struct {\n\t// A human-readable message providing more details about the error.\n\tMessage string `json:\"message\"`\n\t// The type of error that occurred (e.g., \"invalid_request_error\").\n\tType string `json:\"type\"`\n\t// A short code identifying the error, if applicable.\n\tCode string `json:\"code,omitempty\"`\n}\n```\nErrorDetail provides specific information about an error that occurred. It includes a human-readable message, an error type, and an optional error code.\n\n```go\ntype ErrorResponse struct {\n\tError ErrorDetail `json:\"error\"`\n}\n```\nErrorResponse represents a standard error response format for the API. It contains a single ErrorDetail field.\n\n```go\ntype Server struct {\n\t// contains filtered or unexported fields\n}\n```\nServer represents the main API server. It encapsulates the Gin engine, HTTP server, handlers, and configuration.\n\n```go\nfunc NewServer(cfg *config.Config, cliClients []*client.Client) *Server\n```\nNewServer creates and initializes a new API server instance. It sets up the Gin engine, middleware, routes, and handlers.\n\n```go\nfunc (s *Server) Start() error\n```\nStart begins listening for and serving HTTP requests. It's a blocking call and will only return on an unrecoverable error.\n\n```go\nfunc (s *Server) Stop(ctx context.Context) error\n```\nStop gracefully shuts down the API server without interrupting any active connections.\n\n","path":"github.com/luispater/CLIProxyAPI/internal/api","name":"api","synopsis":"","isRedistributable":true}
