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
+42
View File
@@ -0,0 +1,42 @@
package responses
import "encoding/json"
// Request is an OpenAI Responses API request. The gateway only needs the
// model + stream fields for routing; the full body passes through raw.
type Request struct {
Model string `json:"model"`
Stream bool `json:"stream"`
Instructions json.RawMessage `json:"instructions"`
Input json.RawMessage `json:"input"`
MaxOutputTokens *int `json:"max_output_tokens"`
PreviousResponseID string `json:"previous_response_id"`
Tools json.RawMessage `json:"tools"`
Reasoning json.RawMessage `json:"reasoning"`
Text json.RawMessage `json:"text"`
OutputFormat json.RawMessage `json:"output_format"`
}
// Response is the non-stream Responses response.
type Response struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Status string `json:"status"`
Output json.RawMessage `json:"output"`
Usage *Usage `json:"usage,omitempty"`
}
type Usage struct {
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
TotalTokens int64 `json:"total_tokens"`
InputTokensDetails UsageDetails `json:"input_tokens_details,omitempty"`
OutputTokensDetails UsageDetails `json:"output_tokens_details,omitempty"`
}
type UsageDetails struct {
CachedTokens int64 `json:"cached_tokens,omitempty"`
ReasoningTokens int64 `json:"reasoning_tokens,omitempty"`
}