virtualserver

package
v0.260507.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package virtualserver provides the HTTP handler for virtual model endpoints. It serves OpenAI Chat and Anthropic Messages API formats backed by separate per-provider virtual model registries.

This is the production HTTP surface for internal/virtualmodel: the parent server mounts it under /virtual/v1/* so end users can reach the synthetic provider for onboarding, demos, and dry-runs without configuring a real upstream provider. Test consumers do not depend on this package; they use the registry primitives in internal/virtualmodel directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnthropicContent

type AnthropicContent struct {
	Type  string          `json:"type"`
	Text  string          `json:"text,omitempty"`
	ID    string          `json:"id,omitempty"`
	Name  string          `json:"name,omitempty"`
	Input json.RawMessage `json:"input,omitempty"`
}

AnthropicContent is a content block in an Anthropic response.

type AnthropicDelta

type AnthropicDelta struct {
	Type       string `json:"type,omitempty"`
	Text       string `json:"text,omitempty"`
	StopReason string `json:"stop_reason,omitempty"`
}

AnthropicDelta is a delta in an Anthropic streaming response.

type AnthropicMessage

type AnthropicMessage = anthropic.BetaMessageParam

Request types aliased from protocol / Anthropic SDK

type AnthropicMessageRequest

type AnthropicMessageRequest = protocol.AnthropicBetaMessagesRequest

Request types aliased from protocol / Anthropic SDK

type AnthropicMessageResponse

type AnthropicMessageResponse struct {
	ID         string             `json:"id"`
	Type       string             `json:"type"`
	Role       string             `json:"role"`
	Model      string             `json:"model"`
	Content    []AnthropicContent `json:"content"`
	StopReason string             `json:"stop_reason"`
	Usage      AnthropicUsage     `json:"usage"`
}

AnthropicMessageResponse is an Anthropic-compatible message response.

type AnthropicStreamEvent

type AnthropicStreamEvent struct {
	Type    string                    `json:"type"`
	Message *AnthropicMessageResponse `json:"message,omitempty"`
	Index   int                       `json:"index,omitempty"`
	Delta   *AnthropicDelta           `json:"delta,omitempty"`
	Usage   *AnthropicUsage           `json:"usage,omitempty"`
}

AnthropicStreamEvent is a streaming event in Anthropic format.

type AnthropicTool

type AnthropicTool = anthropic.BetaToolParam

Request types aliased from protocol / Anthropic SDK

type AnthropicUsage

type AnthropicUsage struct {
	InputTokens  int64 `json:"input_tokens"`
	OutputTokens int64 `json:"output_tokens"`
}

AnthropicUsage holds token usage in Anthropic format.

type ChatCompletionRequest

type ChatCompletionRequest = protocol.OpenAIChatCompletionRequest

ChatCompletionRequest is an OpenAI-compatible chat completion request.

type ChatCompletionResponse

type ChatCompletionResponse = openai.ChatCompletion

Response types aliased from OpenAI SDK

type ChatCompletionStreamResponse

type ChatCompletionStreamResponse = openai.ChatCompletionChunk

Response types aliased from OpenAI SDK

type Choice

Response types aliased from OpenAI SDK

type Delta

Response types aliased from OpenAI SDK

type FunctionCall

Response types aliased from OpenAI SDK

type Handler

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

Handler handles HTTP requests for virtual model endpoints.

func NewHandler

func NewHandler(anthropicReg *anthropicvm.Registry, openaiReg *openaivm.Registry) *Handler

NewHandler creates a new Handler backed by the given per-provider registries.

func (*Handler) ChatCompletions

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

ChatCompletions handles POST /virtual/v1/chat/completions.

func (*Handler) ListModels

func (h *Handler) ListModels(c *gin.Context)

ListModels handles GET /virtual/v1/models — returns the union of both registries.

func (*Handler) Messages

func (h *Handler) Messages(c *gin.Context)

Messages handles POST /virtual/v1/messages (Anthropic format).

Accepts both Anthropic v1 and beta wire formats. The query parameter "beta=true" mirrors the real Anthropic API gating used in internal/server/anthropic.go. Internally everything is canonicalized to the beta superset struct so vmodel implementations only deal with one request shape.

type Message

type Message = openai.ChatCompletionMessage

Response types aliased from OpenAI SDK

type OpenAIModelsResponse

type OpenAIModelsResponse struct {
	Object string               `json:"object"`
	Data   []virtualmodel.Model `json:"data"`
}

OpenAIModelsResponse is the OpenAI models list response format.

type Service

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

Service manages the virtual model service.

Each protocol has its own registry. A model registered in the Anthropic registry is callable only via /messages; a model in the OpenAI registry is callable only via /chat/completions. ID collisions across the two registries are intentional and legal — the registry IS the protocol context.

func NewService

func NewService() *Service

NewService creates a fully initialized Service with default models registered in both protocol registries.

func (*Service) GetAnthropicRegistry

func (s *Service) GetAnthropicRegistry() *anthropicvm.Registry

GetAnthropicRegistry returns the Anthropic-protocol model registry.

func (*Service) GetHandler

func (s *Service) GetHandler() *Handler

GetHandler returns the HTTP handler.

func (*Service) GetOpenAIRegistry

func (s *Service) GetOpenAIRegistry() *openaivm.Registry

GetOpenAIRegistry returns the OpenAI Chat-protocol model registry.

func (*Service) SetupRoutes

func (s *Service) SetupRoutes(group *gin.RouterGroup)

SetupRoutes sets up virtual model routes on a Gin router group.

type StreamChoice

type StreamChoice = openai.ChatCompletionChunkChoice

Response types aliased from OpenAI SDK

type ToolCall

Response types aliased from OpenAI SDK

type Usage

type Usage = openai.CompletionUsage

Response types aliased from OpenAI SDK

Jump to

Keyboard shortcuts

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