{"record":{"id":"52992ef21d9c22c7","repo":"plandex-ai/plandex","slug":"error-starting-reply-stream-v","errorCode":null,"errorMessage":"Error starting reply stream: %v","messagePattern":"Error starting reply stream: (.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/model/plan/tell_exec.go","lineNumber":571,"sourceCode":"\t// output the modelReq to a json file\n\t// if jsonData, err := json.MarshalIndent(modelReq, \"\", \"  \"); err == nil {\n\t// \ttimestamp := time.Now().Format(\"2006-01-02-150405\")\n\t// \tfilename := fmt.Sprintf(\"generations/model-request-%s.json\", timestamp)\n\t// \tif err := os.WriteFile(filename, jsonData, 0644); err != nil {\n\t// \t\tlog.Printf(\"Error writing model request to file: %v\\n\", err)\n\t// \t}\n\t// } else {\n\t// \tlog.Printf(\"Error marshaling model request to JSON: %v\\n\", err)\n\t// }\n\n\tlog.Printf(\"[Tell] doTellRequest retry=%d fallbackRetry=%d using model=%s\",\n\t\tstate.numErrorRetry, state.numFallbackRetry, baseModelConfig.ModelName)\n\n\t// start the stream\n\tstream, err := model.CreateChatCompletionStream(clients, authVars, modelConfig, state.settings, state.orgUserConfig, state.currentOrgId, state.currentUserId, active.ModelStreamCtx, modelReq)\n\tif err != nil {\n\t\tlog.Printf(\"Error starting reply stream: %v\\n\", err)\n\t\tgo notify.NotifyErr(notify.SeverityError, fmt.Errorf(\"error starting reply stream: %v\", err))\n\t\tactive.StreamDoneCh <- &shared.ApiError{\n\t\t\tType:   shared.ApiErrorTypeOther,\n\t\t\tStatus: http.StatusInternalServerError,\n\t\t\tMsg:    \"Error starting reply stream: \" + err.Error(),\n\t\t}\n\t\treturn\n\t}\n\n\t// handle stream chunks\n\tgo state.listenStream(stream)\n}\n\nfunc (state *activeTellStreamState) dryRunCalculateTokensWithoutContext(tentativeMaxTokens int, unfinishedSubtaskReasoning string) (bool, int) {\n\tclone := &activeTellStreamState{\n\t\tmodelStreamId:       state.modelStreamId,\n\t\tclients:             state.clients,\n\t\treq:                 state.req,\n\t\tauth:                state.auth,","sourceCodeStart":553,"sourceCodeEnd":589,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/model/plan/tell_exec.go#L553-L589","documentation":"Thrown when model.CreateChatCompletionStream fails to open the streaming connection to the LLM provider. Any provider-side rejection — invalid API key, bad model name, network failure, quota exhaustion — surfaces here. The error is wrapped into an ApiError with the underlying message appended and sent on StreamDoneCh.","triggerScenarios":"CreateChatCompletionStream returns a non-nil err: expired/invalid provider API key, unknown/disabled model for the account, provider outage, DNS/proxy failure, or malformed request built from the messages.","commonSituations":"Rotated or missing OPENAI_API_KEY / ANTHROPIC_API_KEY auth vars; provider rate-limit or account suspension; corporate proxy blocking api.openai.com; model deprecated by provider after an upgrade.","solutions":["Read the wrapped underlying error in the ApiError message to identify the provider cause","Verify the provider API key/auth vars are valid and have quota","Test network/proxy access to the provider endpoint from the server host","Confirm the configured model name is still offered by the provider","Retry after backoff if the provider reported 429/5xx"],"exampleFix":"// before\nauthVars[\"OPENAI_API_KEY\"] = \"\" // rotated out\n// after\nauthVars[\"OPENAI_API_KEY\"] = os.Getenv(\"OPENAI_API_KEY\") // valid key set before calling Tell","handlingStrategy":"retry","validationCode":"// pre-flight provider auth check\nif authVars[providerKeyEnv] == \"\" {\n    return fmt.Errorf(\"%s is not set; cannot start stream\", providerKeyEnv)\n}","typeGuard":null,"tryCatchPattern":"if apiErr := <-active.StreamDoneCh; apiErr != nil && strings.HasPrefix(apiErr.Msg, \"Error starting reply stream:\") {\n    cause := strings.TrimPrefix(apiErr.Msg, \"Error starting reply stream: \")\n    if strings.Contains(cause, \"429\") || strings.Contains(cause, \"timeout\") {\n        // retry with exponential backoff\n    } else if strings.Contains(cause, \"401\") {\n        // refresh API key\n    }\n}","preventionTips":["Validate provider API keys before starting sessions","Add retry with backoff for transient 429/5xx stream errors","Monitor provider status pages and set fallback model packs","Verify server egress/proxy access to provider endpoints"],"tags":["network","llm","streaming","api-key"],"backgroundTag":"llm-stream-connection-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}