The only tool you need to know what is happening and how to fix it.
Go alertingexception-trackerissue-trackinglogsmetricsmonitoringobservability-platformopen-telemetryotelsession-replaytelemetrytraces
feat(devtesting-embedded): add Cheaper Inference as a named chat gateway option (#407)
aiapienthusiast506df6db4fde
diff --git a/examples/devtesting-embedded/README.md b/examples/devtesting-embedded/README.mdindex 2aef6ee1..0a66c077 100644--- a/examples/devtesting-embedded/README.md+++ b/examples/devtesting-embedded/README.md@@ -10,7 +10,7 @@ go run .Then:- App: http://localhost:8080/cdn (no build step) or http://localhost:8080 (requires `cd frontend && npm install && npm run build` first)-- AI chat: http://localhost:8080/chat (needs `ORCAROUTER_API_KEY` or `OPENROUTER_API_KEY` in `.env`)+- AI chat: http://localhost:8080/chat (needs `ORCAROUTER_API_KEY`, `CHEAPER_INFERENCE_API_KEY` or `OPENROUTER_API_KEY` in `.env`)- Dashboard: http://localhost:8082 — login `[email protected]` / `admin`## AI chat (conversations, tool calls, sub-agents)@@ -22,12 +22,16 @@ Then:ORCAROUTER_API_KEY=sk-orca-...ORCAROUTER_MODEL=orcarouter/auto+# Cheaper Inference (https://cheaperinference.com)+# CHEAPER_INFERENCE_API_KEY=ci_live_...+# CHEAPER_INFERENCE_MODEL=gpt-5.4-mini+# OpenRouter — fallback provider# OPENROUTER_API_KEY=sk-or-...# OPENROUTER_MODEL=anthropic/claude-sonnet-5```-When `ORCAROUTER_API_KEY` is set the chat routes through [OrcaRouter](https://www.orcarouter.ai) (`https://api.orcarouter.ai/v1`); otherwise it falls back to OpenRouter.+When `ORCAROUTER_API_KEY` is set the chat routes through [OrcaRouter](https://www.orcarouter.ai) (`https://api.orcarouter.ai/v1`). When `CHEAPER_INFERENCE_API_KEY` is set instead, it routes through [Cheaper Inference](https://cheaperinference.com) (`https://api.cheaperinference.com/v1`). Otherwise it falls back to OpenRouter.How it maps to Traceway:diff --git a/examples/devtesting-embedded/ai.go b/examples/devtesting-embedded/ai.goindex 14ee9819..3bf15c22 100644--- a/examples/devtesting-embedded/ai.go+++ b/examples/devtesting-embedded/ai.go@@ -19,18 +19,22 @@ import ("go.opentelemetry.io/otel/trace")-// An AI chat agent backed by OpenRouter or OrcaRouter, instrumented with-// gen_ai.* span attributes so every LLM call lands in Traceway's AI Traces /-// Conversations analytics: conversation grouping (gen_ai.conversation.id),-// per-user stats (user.id), tool calls parsed from the completion payload, and-// sub-agents as separate trace names inside the same conversation.+// An AI chat agent backed by OpenRouter, OrcaRouter or Cheaper Inference,+// instrumented with gen_ai.* span attributes so every LLM call lands in+// Traceway's AI Traces / Conversations analytics: conversation grouping+// (gen_ai.conversation.id), per-user stats (user.id), tool calls parsed from+// the completion payload, and sub-agents as separate trace names inside the+// same conversation.//// The provider is selected by environment: setting ORCAROUTER_API_KEY routes-// through OrcaRouter (https://api.orcarouter.ai/v1), otherwise the agent falls-// back to OpenRouter.+// through OrcaRouter (https://api.orcarouter.ai/v1), setting+// CHEAPER_INFERENCE_API_KEY routes through Cheaper Inference+// (https://api.cheaperinference.com/v1), otherwise the agent falls back to+// OpenRouter.const openRouterURL = "https://openrouter.ai/api/v1/chat/completions"const orcaRouterURL = "https://api.orcarouter.ai/v1/chat/completions"+const cheaperInferenceURL = "https://api.cheaperinference.com/v1/chat/completions"var aiHTTPClient = &http.Client{Timeout: 120 * time.Second}@@ -194,11 +198,14 @@ type toolEvent struct {// callGateway makes one chat-completions call and emits the gen_ai.* span// Traceway promotes to an ai_traces row. The gateway is selected by env:-// ORCAROUTER_API_KEY routes through OrcaRouter, otherwise OpenRouter is used.+// ORCAROUTER_API_KEY routes through OrcaRouter, CHEAPER_INFERENCE_API_KEY+// routes through Cheaper Inference, otherwise OpenRouter is used.func (cc *chatContext) callGateway(ctx context.Context, agent agentDef, messages []orMessage) (*orResponse, error) {endpoint, apiKey, system := openRouterURL, os.Getenv("OPENROUTER_API_KEY"), "openrouter"if os.Getenv("ORCAROUTER_API_KEY") != "" {endpoint, apiKey, system = orcaRouterURL, os.Getenv("ORCAROUTER_API_KEY"), "orcarouter"+ } else if os.Getenv("CHEAPER_INFERENCE_API_KEY") != "" {+ endpoint, apiKey, system = cheaperInferenceURL, os.Getenv("CHEAPER_INFERENCE_API_KEY"), "cheaperinference"}reqBody := orRequest{Model: cc.model, Messages: messages, Tools: agent.Tools}@@ -549,6 +556,12 @@ func defaultModel() string {}return "orcarouter/auto"}+ if os.Getenv("CHEAPER_INFERENCE_API_KEY") != "" {+ if model := os.Getenv("CHEAPER_INFERENCE_MODEL"); model != "" {+ return model+ }+ return "gpt-5.4-mini"+ }if model := os.Getenv("OPENROUTER_MODEL"); model != "" {return model}@@ -559,8 +572,8 @@ func registerAIChatRoutes(router *gin.Engine, svc *otelService) {model := defaultModel()router.POST("/api/ai/chat", func(c *gin.Context) {- if os.Getenv("ORCAROUTER_API_KEY") == "" && os.Getenv("OPENROUTER_API_KEY") == "" {- c.JSON(http.StatusServiceUnavailable, gin.H{"error": "ORCAROUTER_API_KEY or OPENROUTER_API_KEY is not set; add it to examples/devtesting-embedded/.env"})+ if os.Getenv("ORCAROUTER_API_KEY") == "" && os.Getenv("CHEAPER_INFERENCE_API_KEY") == "" && os.Getenv("OPENROUTER_API_KEY") == "" {+ c.JSON(http.StatusServiceUnavailable, gin.H{"error": "ORCAROUTER_API_KEY, CHEAPER_INFERENCE_API_KEY or OPENROUTER_API_KEY is not set; add it to examples/devtesting-embedded/.env"})return}diff --git a/examples/devtesting-embedded/main.go b/examples/devtesting-embedded/main.goindex 099eeb60..7d5b7181 100644--- a/examples/devtesting-embedded/main.go+++ b/examples/devtesting-embedded/main.go@@ -138,8 +138,9 @@ func (s *otelService) log(ctx context.Context, sev otellog.Severity, sevText, bo}func main() {- // ORCAROUTER_API_KEY / ORCAROUTER_MODEL (or OPENROUTER_API_KEY /- // OPENROUTER_MODEL) for the AI chat live in .env.+ // ORCAROUTER_API_KEY / ORCAROUTER_MODEL (or CHEAPER_INFERENCE_API_KEY /+ // CHEAPER_INFERENCE_MODEL, or OPENROUTER_API_KEY / OPENROUTER_MODEL) for the+ // AI chat live in .env._ = godotenv.Load()go tracewaybackend.Run(@@ -396,9 +397,9 @@ func main() {fmt.Printf(" AI chat: http://localhost:%d/chat\n", appPort)fmt.Println(" Dashboard: http://localhost:8082")fmt.Println(" Login: [email protected] / admin")- if os.Getenv("ORCAROUTER_API_KEY") == "" && os.Getenv("OPENROUTER_API_KEY") == "" {+ if os.Getenv("ORCAROUTER_API_KEY") == "" && os.Getenv("CHEAPER_INFERENCE_API_KEY") == "" && os.Getenv("OPENROUTER_API_KEY") == "" {fmt.Println()- fmt.Println(" WARNING: ORCAROUTER_API_KEY / OPENROUTER_API_KEY is not set (.env) — /chat will not work")+ fmt.Println(" WARNING: ORCAROUTER_API_KEY / CHEAPER_INFERENCE_API_KEY / OPENROUTER_API_KEY is not set (.env) — /chat will not work")}fmt.Println()fmt.Println(" OTel logs test endpoints (hit with curl or browser):")