plandex-ai/plandex · error

error unmarshalling AZURE_DEPLOYMENTS_MAP: %w

Error message

error unmarshalling AZURE_DEPLOYMENTS_MAP: %w

What it means

For Azure OpenAI deployments the library reads the AZURE_DEPLOYMENTS_MAP auth var, expected to be a JSON object mapping model names to Azure deployment names, and unmarshals it with json.Unmarshal. If the env var holds invalid JSON, the request fails with "error unmarshalling AZURE_DEPLOYMENTS_MAP: %w" wrapping the json error.

Source

Thrown at app/server/model/client.go:259

		if authVars["VERTEXAI_LOCATION"] != "" {
			extendedReq.VertexLocation = authVars["VERTEXAI_LOCATION"]
		}
		if authVars["GOOGLE_APPLICATION_CREDENTIALS"] != "" {
			extendedReq.VertexCredentials = authVars["GOOGLE_APPLICATION_CREDENTIALS"]
		}
	case shared.ModelProviderAzureOpenAI:
		if authVars["AZURE_API_BASE"] != "" {
			extendedReq.LiteLLMApiBase = authVars["AZURE_API_BASE"]
		}
		if authVars["AZURE_API_VERSION"] != "" {
			extendedReq.AzureApiVersion = authVars["AZURE_API_VERSION"]
		}

		if authVars["AZURE_DEPLOYMENTS_MAP"] != "" {
			var azureDeploymentsMap map[string]string
			err := json.Unmarshal([]byte(authVars["AZURE_DEPLOYMENTS_MAP"]), &azureDeploymentsMap)
			if err != nil {
				return nil, fmt.Errorf("error unmarshalling AZURE_DEPLOYMENTS_MAP: %w", err)
			}
			modelName := string(extendedReq.Model)
			modelName = strings.ReplaceAll(modelName, "azure/", "")

			deploymentName, ok := azureDeploymentsMap[modelName]
			if ok {
				log.Println("azure - deploymentName", deploymentName)
				modelName = "azure/" + deploymentName
				extendedReq.Model = shared.ModelName(modelName)
			}
		}

		// azure uses 'reasoning_config' instead of 'reasoning' like direct openai api
		if extendedReq.ReasoningConfig != nil {
			extendedReq.AzureReasoningEffort = extendedReq.ReasoningConfig.Effort
			extendedReq.ReasoningConfig = nil
		}
	case shared.ModelProviderAmazonBedrock:

View on GitHub (pinned to e2d772072e)

Solutions

  1. Validate the env var with jq before use: echo "$AZURE_DEPLOYMENTS_MAP" | jq -e 'type == "object"' — fix the JSON until it passes.
  2. Ensure the value is a JSON object of string-to-string, using double quotes inside, e.g. {"gpt-4o":"my-deployment"}.
  3. In docker-compose/K8s, quote the value so inner double quotes survive; prefer a JSON env file over inline shell.
  4. Optionally parse at startup (not per-request) so misconfiguration fails immediately with a clear message.

Example fix

// before
AZURE_DEPLOYMENTS_MAP = {'gpt-4o': 'gpt-4o-deploy'}   // invalid JSON -> unmarshal error
// after
AZURE_DEPLOYMENTS_MAP = '{"gpt-4o": "gpt-4o-deploy"}'  // valid JSON object
Defensive patterns

Strategy: validation

Validate before calling

// validate before starting/sending requests
val := os.Getenv("AZURE_DEPLOYMENTS_MAP")
if val != "" {
    var m map[string]string
    if err := json.Unmarshal([]byte(val), &m); err != nil {
        panic(fmt.Sprintf("AZURE_DEPLOYMENTS_MAP is not valid JSON: %v", err))
    }
}

Type guard

func isValidDeploymentsMap(s string) bool {
    if s == "" {
        return true
    }
    var m map[string]string
    return json.Unmarshal([]byte(s), &m) == nil
}

Try / catch

resp, err := client.CreateChatCompletionStream(ctx, req)
if err != nil && strings.Contains(err.Error(), "AZURE_DEPLOYMENTS_MAP") {
    return fmt.Errorf("fix AZURE_DEPLOYMENTS_MAP: must be a JSON object like {\"gpt-4o\":\"my-deploy\"}: %w", err)
}

Prevention

When it happens

Trigger: createChatCompletionStreamExtended runs with baseModelConfig.Provider == AzureOpenAI and authVars["AZURE_DEPLOYMENTS_MAP"] is non-empty but not valid JSON (e.g. single-quoted keys, trailing comma, YAML, or shell-mangled quoting) so json.Unmarshal into map[string]string fails.

Common situations: Setting AZURE_DEPLOYMENTS_MAP='{"gpt-4o": "gpt-4o-deploy"}' with single quotes eaten by the shell; pasting a YAML-style mapping; values containing characters that break map[string]string (non-string values); shell escaping stripping inner double quotes in docker/compose env files.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/26ddd371dea31212. Report an issue: GitHub.