feat(server): API relay gateway backend M0-M4

Gin + GORM + pure-Go SQLite. Users/auth (JWT), API key management with
quotas, proxy gateway with weighted channel failover and health checks,
usage/billing ledger, cross-protocol conversion (Anthropic Messages /
OpenAI Chat Completions / OpenAI Responses), and channel/model admin API.
Channels declare native API formats and auto-convert the rest.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Sakurasan
2026-08-15 21:05:02 +08:00
co-authored by Claude Sonnet 5
parent b0c7439c01
commit d0e31b198f
45 changed files with 6222 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
package claude
import "encoding/json"
// Request is an Anthropic Messages request.
type Request struct {
Model string `json:"model"`
MaxTokens int `json:"max_tokens"`
Stream bool `json:"stream"`
System json.RawMessage `json:"system"`
Messages json.RawMessage `json:"messages"`
Temperature *float64 `json:"temperature"`
TopP *float64 `json:"top_p"`
TopK *int `json:"top_k"`
StopSequences json.RawMessage `json:"stop_sequences"`
Tools json.RawMessage `json:"tools"`
ToolChoice json.RawMessage `json:"tool_choice"`
Metadata json.RawMessage `json:"metadata"`
}
// Usage is the Claude usage block.
type Usage struct {
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
CacheReadInputTokens int64 `json:"cache_read_input_tokens,omitempty"`
CacheCreationInputTokens int64 `json:"cache_creation_input_tokens,omitempty"`
}
// MessageResponse is the non-stream response.
type MessageResponse struct {
ID string `json:"id"`
Type string `json:"type"`
Role string `json:"role"`
Model string `json:"model"`
Content json.RawMessage `json:"content"`
StopReason string `json:"stop_reason"`
StopSequence string `json:"stop_sequence"`
Usage *Usage `json:"usage"`
}
// StreamEvent is one event in the Claude streaming event sequence.
type StreamEvent struct {
Type string `json:"type"`
Message json.RawMessage `json:"message,omitempty"`
Index *int `json:"index,omitempty"`
Delta json.RawMessage `json:"delta,omitempty"`
Usage json.RawMessage `json:"usage,omitempty"`
ContentBlock json.RawMessage `json:"content_block,omitempty"`
Error json.RawMessage `json:"error,omitempty"`
}