{"record":{"id":"82881b1f3a2c843a","repo":"BerriAI/litellm","slug":"togetheraiexception-error-str","errorCode":null,"errorMessage":"TogetherAIException - {error_str}","messagePattern":"TogetherAIException - (.+?)","errorType":"exception","errorClass":"Timeout","httpStatus":408,"severity":"warning","filePath":"litellm/litellm_core_utils/exception_mapping_utils.py","lineNumber":1683,"sourceCode":"            llm_provider=\"together_ai\",\n            response=getattr(original_exception, \"response\", None),\n        )\n    elif \"error\" in error_response and \"invalid private key\" in error_response[\"error\"]:\n        raise AuthenticationError(\n            message=f\"TogetherAIException - {error_response['error']}\",\n            llm_provider=\"together_ai\",\n            model=model,\n            response=getattr(original_exception, \"response\", None),\n        )\n    elif \"error\" in error_response and \"INVALID_ARGUMENT\" in error_response[\"error\"]:\n        raise BadRequestError(\n            message=f\"TogetherAIException - {error_response['error']}\",\n            model=model,\n            llm_provider=\"together_ai\",\n            response=getattr(original_exception, \"response\", None),\n        )\n    elif \"A timeout occurred\" in error_str:\n        raise Timeout(\n            message=f\"TogetherAIException - {error_str}\",\n            model=model,\n            llm_provider=\"together_ai\",\n        )\n    elif (\n        \"error\" in error_response\n        and \"API key doesn't match expected format.\" in error_response[\"error\"]\n        or \"error_type\" in error_response\n        and error_response[\"error_type\"] == \"validation\"\n    ):\n        raise BadRequestError(\n            message=f\"TogetherAIException - {error_response['error']}\",\n            model=model,\n            llm_provider=\"together_ai\",\n            response=getattr(original_exception, \"response\", None),\n        )\n    if hasattr(original_exception, \"status_code\"):\n        if original_exception.status_code == 408:","sourceCodeStart":1665,"sourceCodeEnd":1701,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/exception_mapping_utils.py#L1665-L1701","documentation":"This is a litellm Timeout raised by the Together AI exception mapper when the raw error string contains 'A timeout occurred'. Together AI returns this textual message when the request exceeds its processing time limit; litellm matches it by substring on error_str (the raw body, not the parsed JSON) and raises the retryable Timeout class with the 'TogetherAIException - ' prefix.","triggerScenarios":"Long generations on big Together models (70B-class) that exceed Together's server-side time budget; overloaded queues for popular models; huge prompts slowing prefill.","commonSituations":"High max_tokens on 70B models at peak hours; retry loops amplifying load; batch inference without time budgets.","solutions":["Retry with backoff — timeouts are frequently transient","Reduce max_tokens or prompt size to fit the time budget","Set num_retries=3 on the call","Try a smaller/faster Together model or off-peak scheduling"],"exampleFix":"# before\nlitellm.completion(model=\"together_ai/llama-2-70b\", messages=msgs, max_tokens=2048)\n\n# after\nlitellm.completion(\n    model=\"together_ai/llama-2-70b\", messages=msgs,\n    max_tokens=512, num_retries=3,\n)","handlingStrategy":"retry","validationCode":null,"typeGuard":"def is_together_timeout(e: Exception) -> bool:\n    return (\n        isinstance(e, litellm.Timeout)\n        and getattr(e, \"llm_provider\", \"\") == \"together_ai\"\n    )","tryCatchPattern":"try:\n    resp = litellm.completion(model=m, messages=msgs, num_retries=3, retry_after=2)\nexcept litellm.Timeout:\n    logger.warning(\"Together AI timed out\")\n    raise","preventionTips":["Set num_retries so 'A timeout occurred' errors retry automatically","Keep max_tokens realistic for the model's speed","Offload very long generations to async jobs instead of long HTTP calls"],"tags":["together-ai","timeout","retryable","litellm"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}