{"record":{"id":"7587bdb59d4d15f2","repo":"rohitg00/ai-engineering-from-scratch","slug":"independent-requests-must-be-positive","errorCode":null,"errorMessage":"independent_requests must be positive","messagePattern":"independent_requests must be positive","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"certifications/claude/lessons/08-messages-api-and-application-lifecycle/code/main.py","lineNumber":43,"sourceCode":"    messages: list[dict[str, Any]]\n    turns: int\n\n\n@dataclass(frozen=True)\nclass AccessNeeds:\n    \"\"\"Workload facts used to choose a client and completion pattern.\"\"\"\n\n    supported_sdk: bool = True\n    custom_transport: bool = False\n    progressive_output: bool = False\n    independent_requests: int = 1\n    can_wait: bool = False\n\n\ndef choose_access_pattern(needs: AccessNeeds) -> dict[str, str]:\n    \"\"\"Choose SDK versus REST separately from sync, stream, or batch.\"\"\"\n    if needs.independent_requests < 1:\n        raise ValueError(\"independent_requests must be positive\")\n    if needs.progressive_output and needs.can_wait and needs.independent_requests > 1:\n        raise ValueError(\"message batches do not provide progressive per-token output\")\n\n    client = \"raw-rest\" if needs.custom_transport or not needs.supported_sdk else \"sdk\"\n    if needs.can_wait and needs.independent_requests > 1:\n        delivery = \"message-batch\"\n    elif needs.progressive_output:\n        delivery = \"streaming\"\n    else:\n        delivery = \"synchronous\"\n    return {\"client\": client, \"delivery\": delivery}\n\n\nclass ScriptedTransport:\n    \"\"\"A stateless transport that returns scripted API responses.\"\"\"\n\n    def __init__(self, responses: list[dict[str, Any]]) -> None:\n        self._responses = copy.deepcopy(responses)","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/08-messages-api-and-application-lifecycle/code/main.py#L25-L61","documentation":"Precondition on choose_access_pattern: AccessNeeds.independent_requests counts the separate requests in the workload, and a value below 1 (zero or negative) describes no work at all, so the client/delivery recommendation would be undefined.","triggerScenarios":"Thrown at certifications/claude/lessons/08-messages-api-and-application-lifecycle/code/main.py:43 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set independent_requests to the actual number of parallel requests (>= 1)","Treat zero requests as 'nothing to send' and skip calling the chooser","Validate the AccessNeeds values in a single construction-time check"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}