{"record":{"id":"20eaecf0698bafa5","repo":"plandex-ai/plandex","slug":"s-is-not-a-custom-model-provider-that-exists-or","errorCode":null,"errorMessage":"'%s' is not a custom model provider that exists or is being imported","messagePattern":"'(.+?)' is not a custom model provider that exists or is being imported","errorType":"validation","errorClass":null,"httpStatus":422,"severity":"error","filePath":"app/server/handlers/models.go","lineNumber":202,"sourceCode":"\n\tfor _, provider := range updatedModelsInput.CustomProviders {\n\t\tdbProvider := db.CustomProviderFromApi(provider)\n\t\tdbProvider.Id = provider.Id\n\t\tdbProvider.OrgId = auth.OrgId\n\n\t\ttoUpsertCustomProviders = append(toUpsertCustomProviders, dbProvider)\n\t}\n\n\tfor _, model := range updatedModelsInput.CustomModels {\n\t\t// ensure that providers to upsert are either built-in, being imported, or already exist\n\t\tfor _, provider := range model.Providers {\n\t\t\tif provider.Provider == shared.ModelProviderCustom {\n\t\t\t\t_, exists := existingCustomProviderNames[*provider.CustomProvider]\n\t\t\t\t_, creating := inputProviderNames[*provider.CustomProvider]\n\t\t\t\tif !exists && !creating {\n\t\t\t\t\tmsg := fmt.Sprintf(\"'%s' is not a custom model provider that exists or is being imported\", *provider.CustomProvider)\n\t\t\t\t\tlog.Println(msg)\n\t\t\t\t\thttp.Error(w, msg, http.StatusUnprocessableEntity)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tpc, builtIn := shared.BuiltInModelProviderConfigs[provider.Provider]\n\t\t\t\tif !builtIn {\n\t\t\t\t\tmsg := fmt.Sprintf(\"'%s' is not a built-in model provider\", provider.Provider)\n\t\t\t\t\tlog.Println(msg)\n\t\t\t\t\thttp.Error(w, msg, http.StatusUnprocessableEntity)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif os.Getenv(\"IS_CLOUD\") != \"\" && pc.LocalOnly {\n\t\t\t\t\tmsg := fmt.Sprintf(\"'%s' is a local-only model provider, so it can't be used on Plandex Cloud\", provider.Provider)\n\t\t\t\t\tlog.Println(msg)\n\t\t\t\t\thttp.Error(w, msg, http.StatusUnprocessableEntity)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t}","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/models.go#L184-L220","documentation":"A 422 validation error from UpsertCustomModelsHandler: a custom model in the input declares provider.Provider == shared.ModelProviderCustom with a CustomProvider name that neither already exists in the org's stored providers nor is included in the same request's CustomProviders list. The handler requires custom providers to be imported (in this request) or previously created before a model can reference them.","triggerScenarios":"POST to the upsert endpoint whose CustomModels[].Providers[] has {\"provider\":\"custom\",\"customProvider\":\"my-provider\"} where 'my-provider' was never created and is not present in the request's CustomProviders array (e.g. typo in the name, or referencing a provider deleted by a previous full-replace upsert).","commonSituations":"Typo in customProvider name; sending only CustomModels without the matching CustomProviders in the same payload; a prior upsert omitted the provider and the delete-only-what's-missing logic removed it; switching between orgs that have different stored providers.","solutions":["Add the referenced custom provider definition to the same request's CustomProviders array","Fix the customProvider name to match an existing provider exactly (case-sensitive)","First create the provider via a separate upsert that includes it, then reference it","List current providers (GET custom providers/config) to confirm the exact stored name"],"exampleFix":"// before\n{\"customModels\": [{\"modelId\": \"my-model\", \"providers\": [{\"provider\": \"custom\", \"customProvider\": \"my-provder\"}]}]}\n// after\n{\"customProviders\": [{\"name\": \"my-provider\", \"baseUrl\": \"https://api.example.com\"}], \"customModels\": [{\"modelId\": \"my-model\", \"providers\": [{\"provider\": \"custom\", \"customProvider\": \"my-provider\"}]}]}","handlingStrategy":"validation","validationCode":"// before calling the API, verify every custom-provider reference is defined or being imported\nexisting := map[string]bool{\"my-provider\": true} // fetched from GET custom providers\ninput := map[string]bool{}\nfor _, p := range in.CustomProviders { input[p.Name] = true }\nfor _, m := range in.CustomModels {\n    for _, pr := range m.Providers {\n        if pr.Provider == \"custom\" && !existing[*pr.CustomProvider] && !input[*pr.CustomProvider] {\n            return fmt.Errorf(\"provider %q must be created or included in the same request\", *pr.CustomProvider)\n        }\n    }\n}","typeGuard":"func hasResolvableCustomProvider(name string, existing, importing []string) bool {\n    for _, e := range existing { if e == name { return true } }\n    for _, i := range importing { if i == name { return true } }\n    return false\n}","tryCatchPattern":"// 422 is deterministic — do not retry; fix the payload\nif resp.StatusCode == 422 && strings.Contains(bodyText, \"not a custom model provider that exists or is being imported\") {\n    return fmt.Errorf(\"payload error (no retry): %s\", bodyText)\n}","preventionTips":["Always send providers and their referencing models in the same upsert payload","Remember upsert is full-replace: omitting a stored provider deletes it","Validate provider names against the org's stored list before submitting","Guard against typos with exact-match name checks in config tooling"],"tags":["validation","http-422","custom-providers"],"backgroundTag":"unresolved-provider-reference","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"}