api

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: ISC Imports: 12 Imported by: 0

Documentation

Overview

Package api implements the OpenAI-compatible HTTP API for MaritacaProxy. It exposes /v1/chat/completions, /v1/models, /health and other endpoints compatible with OpenAI SDK clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoCreator added in v0.3.0

type AutoCreator interface {
	CreateOne(ctx context.Context) (*account.Account, error)
}

AutoCreator is the interface implemented by the autocreate.Creator. We use an interface so the server can work without autocreate enabled.

type OpenAIRequest

type OpenAIRequest struct {
	Model             string                         `json:"model"`
	Messages          []map[string]interface{}       `json:"messages"`
	Stream            bool                           `json:"stream"`
	Tools             []tools.FunctionToolDefinition `json:"tools"`
	ToolChoice        interface{}                    `json:"tool_choice"`
	ParallelToolCalls *bool                          `json:"parallel_tool_calls"`
	StreamOptions     *struct {
		IncludeUsage bool `json:"include_usage"`
	} `json:"stream_options"`
}

OpenAIRequest is the OpenAI-compatible chat completion request.

type Server

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

Server is the HTTP API server.

func NewServer

func NewServer(mgr *account.Manager, maritacaURL, apiKey string, authCfg auth.Config) *Server

NewServer constructs a new API server.

func (*Server) AuthMiddleware

func (s *Server) AuthMiddleware(next http.HandlerFunc) http.HandlerFunc

AuthMiddleware wraps the handler with API key authentication.

func (*Server) RegisterDefaultAccountsCreate added in v0.3.0

func (s *Server) RegisterDefaultAccountsCreate(mux *http.ServeMux)

RegisterDefaultAccountsCreate registers the default (no-op) accounts/create handler. Called by main.go when AUTO_ACCOUNT_ENABLED=false.

func (*Server) RegisterRoutes

func (s *Server) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes mounts all API routes on the provided mux. Note: /v1/accounts/create is intentionally NOT registered here so that main.go can override it with the autocreate-enabled version when AUTO_ACCOUNT_ENABLED=true. If autocreate is disabled, the default (not-implemented) handler is registered via RegisterDefaultAccountsCreate.

func (*Server) SetAutoCreator added in v0.3.0

func (s *Server) SetAutoCreator(c AutoCreator)

SetAutoCreator injects an autocreate.Creator for on-demand account creation.

Jump to

Keyboard shortcuts

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