diff options
| author | Chia <Chia@93.nz> | 2026-08-06 15:58:57 +1200 |
|---|---|---|
| committer | Chia <Chia@93.nz> | 2026-08-06 15:58:57 +1200 |
| commit | 3f702084d20b3c3a3ea916f3110e99b22bda60b3 (patch) | |
| tree | 517f76c51025ce1ee085ea4898c60f799e5c37ea /cmd/mockupstream/main.go | |
| parent | 41e322c53d7b4b796eb377d0df9c29ecd10ba431 (diff) | |
feat: complete commercial developer workflowspublish-commercial-control-plane
Add tenant-safe usage observability, prepaid billing controls, API key lifecycle management, Embeddings metering, configurable billing alerts, and resilient provider health propagation. Harden Stripe failure handling, migrations, readiness, and the authenticated control-plane UI with end-to-end verification evidence.
Diffstat (limited to 'cmd/mockupstream/main.go')
| -rw-r--r-- | cmd/mockupstream/main.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/cmd/mockupstream/main.go b/cmd/mockupstream/main.go index cf695bb..7dd5bbf 100644 --- a/cmd/mockupstream/main.go +++ b/cmd/mockupstream/main.go @@ -14,13 +14,44 @@ func main() { address := flag.String("address", "127.0.0.1:18080", "listen address") flag.Parse() mux := http.NewServeMux() + mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) }) + mux.HandleFunc("GET /v1/models", models) mux.HandleFunc("POST /v1/chat/completions", openAI) + mux.HandleFunc("POST /v1/embeddings", embeddings) mux.HandleFunc("POST /v1/messages", anthropic) server := &http.Server{Addr: *address, Handler: mux, ReadHeaderTimeout: 5 * time.Second} log.Printf("mock upstream listening on http://%s", *address) log.Fatal(server.ListenAndServe()) } +func models(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]any{ + "object": "list", + "data": []any{ + map[string]any{"id": "text-embedding-e2e", "object": "model"}, + map[string]any{"id": "chat-e2e", "object": "model"}, + }, + }) +} + +func embeddings(w http.ResponseWriter, r *http.Request) { + var request struct { + Model string `json:"model"` + Input json.RawMessage `json:"input"` + } + if json.NewDecoder(r.Body).Decode(&request) != nil || request.Model == "" || len(request.Input) == 0 { + http.Error(w, "invalid JSON", http.StatusBadRequest) + return + } + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]any{ + "object": "list", "model": request.Model, + "data": []any{map[string]any{"object": "embedding", "index": 0, "embedding": []float64{0.125, -0.25, 0.5, 0.75}}}, + "usage": map[string]int{"prompt_tokens": 6, "total_tokens": 6}, + }) +} + func openAI(w http.ResponseWriter, r *http.Request) { var request struct { Model string `json:"model"` |
