completion_api

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBodyTooLarge = errors.New("request body too large")

ErrBodyTooLarge is returned by readJSONBody when the request exceeds max bytes.

Functions

This section is empty.

Types

type AccountPool

type AccountPool interface {
	PickCandidates() []*cursor_account_sdk.Account
	EnsureAccess(ctx context.Context, id string) (*cursor_account_sdk.Account, error)
	MarkUsed(id string)
	MarkRateLimited(id string)
}

AccountPool is the account rotation surface Server needs. *account_pool.Pool satisfies this interface.

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Model         string                         `json:"model"`
	Messages      []cursor_api_sdk.ChatMessage   `json:"messages"`
	Stream        bool                           `json:"stream"`
	StreamOptions *StreamOptions                 `json:"stream_options,omitempty"`
	N             *int                           `json:"n,omitempty"`
	Tools         []cursor_api_sdk.OpenAIToolDef `json:"tools,omitempty"`
	ToolChoice    json.RawMessage                `json:"tool_choice,omitempty"`
	// Sticky identity fields (otto conversation/identity.ts) — first non-empty wins.
	ConversationID string         `json:"conversation_id,omitempty"`
	ThreadID       string         `json:"thread_id,omitempty"`
	SessionID      string         `json:"session_id,omitempty"`
	User           string         `json:"user,omitempty"`
	Metadata       map[string]any `json:"metadata,omitempty"`
}

ChatCompletionRequest is the OpenAI chat completions body we accept.

func (*ChatCompletionRequest) UnmarshalJSON added in v1.5.0

func (r *ChatCompletionRequest) UnmarshalJSON(data []byte) error

type CompletionsRequest

type CompletionsRequest struct {
	Model         string          `json:"model"`
	Prompt        json.RawMessage `json:"prompt"`
	Stream        bool            `json:"stream"`
	StreamOptions *StreamOptions  `json:"stream_options,omitempty"`
	N             *int            `json:"n,omitempty"`
}

CompletionsRequest is the legacy OpenAI text completions shape.

func (*CompletionsRequest) UnmarshalJSON added in v1.5.0

func (r *CompletionsRequest) UnmarshalJSON(data []byte) error

type Handler

type Handler struct {
	Server *Server
}

Handler serves OpenAI-compatible endpoints.

func (*Handler) Mount

func (h *Handler) Mount(mux *http.ServeMux)

Mount registers AI routes on mux under /ai/v1, plus /v1 and unprefixed aliases.

type Server

type Server struct {
	Pool    AccountPool
	API     UpstreamAPI
	Log     *slog.Logger
	MaxBody int64
	// contains filtered or unexported fields
}

Server holds shared dependencies for OpenAI handlers.

func NewServer

func NewServer(pool *account_pool.Pool, api *cursor_api_sdk.Client, log *slog.Logger) *Server

NewServer wires a concrete pool and API client for handlers / CLI reuse.

func (*Server) ListModels

func (s *Server) ListModels(ctx context.Context) ([]cursor_api_sdk.Model, error)

ListModels returns the cached catalog when fresh; otherwise fetches via the account pool.

type StreamOptions added in v1.5.0

type StreamOptions struct {
	IncludeUsage bool `json:"include_usage"`
}

StreamOptions is the OpenAI stream_options object.

type UpstreamAPI

type UpstreamAPI interface {
	CachedModels() []cursor_api_sdk.Model
	ListModels(ctx context.Context, accessToken string) ([]cursor_api_sdk.Model, error)
	ResolveModelSelection(ctx context.Context, accessToken, modelID string) (cursor_api_sdk.ModelSelection, error)
	StartRun(ctx context.Context, accessToken string, payload *cursor_api_sdk.RunPayload, bridgeTools bool) (*cursor_api_sdk.RunControl, error)
}

UpstreamAPI is the Cursor upstream surface Server needs. *cursor_api_sdk.Client satisfies this interface.

Jump to

Keyboard shortcuts

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