{"record":{"id":"248542cb542c87a9","repo":"BerriAI/litellm","slug":"max-retries-must-be-an-int-248542","errorCode":null,"errorMessage":"max retries must be an int","messagePattern":"max retries must be an int","errorType":"http","errorClass":"AzureOpenAIError","httpStatus":422,"severity":"error","filePath":"litellm/llms/azure/completion/handler.py","lineNumber":141,"sourceCode":"                    client=client,\n                )\n            else:\n                ## LOGGING\n                logging_obj.pre_call(\n                    input=prompt,\n                    api_key=api_key,\n                    additional_args={\n                        \"headers\": {\n                            \"api_key\": api_key,\n                            \"azure_ad_token\": azure_ad_token,\n                        },\n                        \"api_version\": api_version,\n                        \"api_base\": api_base,\n                        \"complete_input_dict\": data,\n                    },\n                )\n                if not isinstance(max_retries, int):\n                    raise AzureOpenAIError(status_code=422, message=\"max retries must be an int\")\n                # init AzureOpenAI Client\n                azure_client: Final = self.get_azure_openai_client(\n                    api_key=api_key,\n                    api_base=api_base,\n                    api_version=api_version,\n                    client=client,\n                    litellm_params=litellm_params,\n                    _is_async=False,\n                    model=model,\n                )\n\n                if not isinstance(azure_client, AzureOpenAI):\n                    raise AzureOpenAIError(\n                        status_code=500,\n                        message=\"azure_client is not an instance of AzureOpenAI\",\n                    )\n\n                raw_response: Final = azure_client.completions.with_raw_response.create(**data, timeout=timeout)","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure/completion/handler.py#L123-L159","documentation":"Before constructing the sync AzureOpenAI SDK client for text completion, LiteLLM pops max_retries from optional_params (default 2) and requires it to be an int; anything else raises AzureOpenAIError 422. The OpenAI SDK's max_retries parameter is passed straight through, so a non-int would fail deeper with a worse message.","triggerScenarios":"Passing max_retries=\"5\" (string from an env var or config file), max_retries=5.0, or None through optional_params to the azure text-completion path.","commonSituations":"Proxy YAML configs where numeric-looking values come from os.environ/<VAR> substitutions that yield strings; JSON configs with float values; templating systems that stringify numbers.","solutions":["Pass an int: litellm.text_completion(..., max_retries=3).","Coerce config-sourced values: max_retries=int(cfg[\"max_retries\"]) with a safe default.","In proxy configs, put the literal integer in YAML rather than an env-string substitution."],"exampleFix":"# before\nmax_retries = os.environ.get(\"MAX_RETRIES\", \"2\")  # str!\n\n# after\nmax_retries = int(os.environ.get(\"MAX_RETRIES\", \"2\"))","handlingStrategy":"type-guard","validationCode":"max_retries = cfg.get(\"max_retries\", 2)\nassert isinstance(max_retries, int) and not isinstance(max_retries, bool), \"max_retries must be int\"","typeGuard":"def is_int_retries(v: object) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool)","tryCatchPattern":"try:\n    resp = litellm.text_completion(..., max_retries=cfg[\"max_retries\"])\nexcept AzureOpenAIError as e:\n    if e.status_code == 422 and \"max retries\" in str(e):\n        resp = litellm.text_completion(..., max_retries=int(cfg[\"max_retries\"]))\n    else:\n        raise","preventionTips":["Coerce config-sourced numbers once at load: int()/float() with defaults.","Keep retry counts as literal ints in YAML, not env-string substitutions.","Add JSON-schema validation (type: integer) for config files."],"tags":["azure","validation","retries","type-error"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}