OpenAI Django Webhooks
Workflow
- Inspect the existing Django service, models, URLs, views, jobs, templates, and OpenAI client use. Preserve the established project conventions.
- Define the lifecycle before you write code. Record the local record ID and the OpenAI response ID. Record the allowed states, terminal failures, duplicate-event behavior, and retry policy.
- Read the Django webhook flow reference. It contains patterns for the service, callback, response extraction, and HTMX polling. Verify each code example against the current official documentation before you use it.
- Assign each action to one component:
- The request endpoint verifies the signature, records the delivery durably, enqueues work, and returns a
2xxresponse promptly. - The worker retrieves the response and handles retryable processing failures.
- The service layer owns idempotent state transitions and output persistence.
- The status view authorizes each request and stops polling after every terminal state.
- The request endpoint verifies the signature, records the delivery durably, enqueues work, and returns a
- Validate signature failures and duplicate delivery. Validate events that are out of order or unknown. Validate retrieval failure, terminal response failure, successful completion, and polling termination. Report exact evidence during diagnosis. Do not infer a cause only from symptoms.
Verify Current Information
Before implementation, use official OpenAI documentation to verify the current Responses API fields and webhook event structures. Also verify the SDK signature-verification helpers, retry behavior, and supported models. Record the documentation URL and access date in the plan or review. Check the current Django and HTMX documentation when behavior depends on their versions. Verify version-sensitive examples before you use them.