{"record":{"id":"9c8093a483718718","repo":"BerriAI/litellm","slug":"missing-model-or-messages-9c8093","errorCode":null,"errorMessage":"Missing model or messages","messagePattern":"Missing model or messages","errorType":"http","errorClass":"AzureOpenAIError","httpStatus":422,"severity":"error","filePath":"litellm/llms/azure/completion/handler.py","lineNumber":53,"sourceCode":"        api_key: str | None,\n        api_base: str,\n        api_version: str,\n        api_type: str,\n        azure_ad_token: str | None,\n        azure_ad_token_provider: Callable | None,\n        print_verbose: Callable,\n        timeout,\n        logging_obj: LiteLLMLoggingObj,\n        optional_params,\n        litellm_params: dict[str, object],\n        logger_fn,\n        acompletion: bool = False,\n        headers: dict | None = None,\n        client=None,\n    ):\n        try:\n            if model is None or messages is None:\n                raise AzureOpenAIError(status_code=422, message=\"Missing model or messages\")\n\n            max_retries: Final = optional_params.pop(\"max_retries\", 2)\n            prompt: Final = prompt_factory(messages=messages, model=model, custom_llm_provider=\"azure_text\")\n\n            ### CHECK IF CLOUDFLARE AI GATEWAY ###\n            ### if so - set the model as part of the base url\n            if api_base is not None and \"gateway.ai.cloudflare.com\" in api_base:\n                ## build base url - assume api base includes resource name\n                client = self._init_azure_client_for_cloudflare_ai_gateway(\n                    api_key=api_key,\n                    api_version=api_version,\n                    api_base=api_base,\n                    model=model,\n                    client=client,\n                    max_retries=max_retries,\n                    timeout=timeout,\n                    azure_ad_token=azure_ad_token,\n                    azure_ad_token_provider=azure_ad_token_provider,","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure/completion/handler.py#L35-L71","documentation":"The Azure text-completion handler validates that both model and messages are non-None before building the request, raising AzureOpenAIError 422 otherwise. The OpenAI-style API fundamentally requires a model identifier and a prompt source, and LiteLLM derives the prompt from messages via prompt_factory.","triggerScenarios":"Calling AzureOpenAITextCompletion.completion() directly (or via litellm.text_completion with the azure provider) with model=None or messages=None; upstream code building the call from unvalidated user input where fields can be missing.","commonSituations":"Dynamic dispatch code that maps request dicts to completion calls and passes missing keys; refactors renaming messages to prompt; API servers forwarding partial payloads without schema validation.","solutions":["Ensure both model and messages are provided: litellm.text_completion(model=\"azure/<deployment>\", prompt=\"hello\", ...).","Validate the request payload at your API boundary (require model + messages/prompt fields) before it reaches LiteLLM.","If calling the class directly, pass every positional/keyword argument the signature expects rather than relying on defaults."],"exampleFix":"# before\nresp = azure_text_llm.completion(messages=None, model=None, ...)\n\n# after\nresp = azure_text_llm.completion(\n    model=\"azure/my-text-deployment\",\n    messages=[{\"role\": \"user\", \"content\": \"hello\"}],\n    ...,\n)","handlingStrategy":"validation","validationCode":"def validate_completion_request(payload: dict) -> None:\n    if not payload.get(\"model\") or not payload.get(\"messages\"):\n        raise RequestValidationError(\"'model' and 'messages' are required\")","typeGuard":"from typing import TypeGuard\n\ndef has_model_and_messages(d: dict) -> TypeGuard[dict]:\n    return isinstance(d.get(\"model\"), str) and isinstance(d.get(\"messages\"), list) and len(d[\"messages\"]) > 0","tryCatchPattern":"try:\n    resp = litellm.text_completion(model=model, prompt=p, ...)\nexcept AzureOpenAIError as e:\n    if e.status_code == 422 and \"Missing model or messages\" in str(e):\n        return bad_request_response()  # 400 to your caller\n    raise","preventionTips":["Validate payloads with pydantic at the API boundary before calling LiteLLM.","Never construct completion calls from raw dicts without key checks.","Write integration tests exercising the minimal-valid request shape."],"tags":["azure","validation","request-validation","text-completion"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}