Initial commit: OpenCode Zen Proxy

Proxy translating OpenAI/Anthropic Messages API to OpenCode Zen's free models.
Pure stdlib Go 1.22, no external dependencies.

- OpenAI Chat Completions (/v1/chat/completions) with streaming
- Anthropic Messages API (/v1/messages) with streaming
- Model aliases for 5 free models
- Auth middleware support
- Session rotation (30min per user key)
This commit is contained in:
renato97
2026-06-25 11:49:11 -03:00
commit 0a4289cafc
11 changed files with 2396 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
package main
import (
"flag"
"fmt"
"os"
"opencode-proxy/internal/proxy"
"opencode-proxy/internal/server"
)
const appVersion = "1.0.0"
func main() {
port := flag.String("port", "", "Server port (default: 6446)")
host := flag.String("host", "", "Server host (default: 127.0.0.1)")
apiKey := flag.String("api-key", "", "API key to protect the proxy (optional, can also be set via OPENCODE_PROXY_KEY env var)")
showVersion := flag.Bool("version", false, "Show version and exit")
flag.Parse()
if *showVersion {
fmt.Printf("opencode-proxy v%s\n", appVersion)
return
}
// Resolve API key: flag takes precedence, then env var
key := *apiKey
if key == "" {
key = os.Getenv("OPENCODE_PROXY_KEY")
}
p := proxy.NewProxy(key)
srv := server.NewServer(p)
if *port != "" {
srv.SetPort(*port)
}
if *host != "" {
srv.SetHost(*host)
}
fmt.Printf("OpenCode Zen Proxy v%s\n", appVersion)
fmt.Printf("Starting on %s:%s\n", srv.Host(), srv.Port())
if key != "" {
fmt.Println("API key protection: ENABLED")
} else {
fmt.Println("API key protection: DISABLED (no key set)")
}
fmt.Printf("Free models available: %d\n", len(p.Models()))
if err := srv.Start(); err != nil {
fmt.Fprintf(os.Stderr, "Server error: %v\n", err)
os.Exit(1)
}
}