{"record":{"id":"8d80675c23853e29","repo":"BerriAI/litellm","slug":"invalid-purpose-purpose-must-be-one-of-valid","errorCode":null,"errorMessage":"Invalid purpose: {purpose}. Must be one of: {valid_purposes}","messagePattern":"Invalid purpose: (.+?)\\. Must be one of: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"litellm/proxy/openai_files_endpoints/files_endpoints.py","lineNumber":367,"sourceCode":"        file_params: Final = await extract_file_creation_params(\n            request=request,\n            request_body=request_body,\n            target_model_names_form=target_model_names,\n            target_storage_form=target_storage,\n        )\n\n        target_storage = file_params.target_storage\n        target_model_names_list: Final = file_params.target_model_names\n        model_param: Final = file_params.model\n\n        validate_managed_files_requirement(target_model_names=target_model_names_list, model=model_param)\n\n        # Prepare the data for forwarding\n\n        # Replace with:\n        valid_purposes: Final = get_args(OpenAIFilesPurpose)\n        if purpose not in valid_purposes:\n            raise HTTPException(\n                status_code=400,\n                detail={\n                    \"error\": f\"Invalid purpose: {purpose}. Must be one of: {valid_purposes}\",\n                },\n            )\n        # Cast purpose to OpenAIFilesPurpose type\n        purpose = cast(OpenAIFilesPurpose, purpose)\n\n        data = {}\n\n        # Parse expires_after if provided\n        expires_after: FileExpiresAfter | None = None\n        form_data_raw: Final = await request.form()\n        form_data_dict: Final[dict[str, Any]] = dict(form_data_raw)\n        extracted_litellm_metadata: Final[dict[str, Any] | None] = extract_nested_form_metadata(\n            form_data=form_data_dict, prefix=\"litellm_metadata[\"\n        )\n        expires_after_anchor: Final = form_data_raw.get(\"expires_after[anchor]\")","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/openai_files_endpoints/files_endpoints.py#L349-L385","documentation":"HTTPException(400) raised while validating the 'purpose' form field on file upload: the supplied purpose is not one of the allowed values (the valid list is included in the message). The OpenAI files API only accepts specific purpose strings; the client must correct the value.","triggerScenarios":"Thrown at litellm/proxy/openai_files_endpoints/files_endpoints.py:367 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use one of the valid purposes listed in the error for the 'purpose' field."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}