Request tracking, timeouts and retries
Save the request ID to avoid repeated generation due to network errors.
Record diagnostic information
Save the request time, model, protocol, HTTP status and X-Oneapi-Request-Id in the response header; if there is X-Upstream-Request-Id, you can also keep it. Do not log full Authorization or sensitive input. The client’s own business ID is stored separately from the gateway request ID.
Timeout layering
Set connection, first byte, streaming idle and total duration limits separately. After the video task is created, it is completed by querying the status. You cannot rely on a long connection to wait indefinitely. The timeout settings of the agent and client must match the business.
Limited retries
Temporary network errors, some 5xx and 429 can be backed off and retried according to actual semantics; 401, 403 and parameter errors should be corrected first. Observe wait time when receiving Retry-After, set maximum number of attempts and add random jitter.
Prevent repeated execution
Charges may apply for model generation and media creation. Timeout does not prove that the upstream did not receive the request; first check the existing task ID and call record. Rely on idempotent keys only when the endpoint explicitly supports them, and you cannot rely on custom request headers to assume that deduplication will work.
When the service has started streaming return, the unfinished output will be marked and restored by the business decision, and the newly generated content will not be automatically spliced into the same answer.
Record a call
curl --fail-with-body --connect-timeout 10 --max-time 120 -D response-headers.txt https://dunduntoken.com/v1/chat/completions -H "Authorization: Bearer $DUNDUN_API_KEY" -H "Content-Type: application/json" -d '{"model":"MODEL_ID","messages":[{"role":"user","content":"只回复 OK"}]}'
Example timeouts are for short text diagnostics and are not recommended values for all tasks. Response headers may contain other sensitive information, which should be checked and desensitized before sharing.
Retry decision
| Situation | Suggestions |
|---|---|
| Clear parameter error | Correct the request and try again |
| Credentials or permissions failed | Stop retrying and check configuration |
| 429 | Read prompts and limited backoff |
| 5xx or connection failure | Determine whether execution has started and then try again with limited time |
| The stream has output part of the content | The mark is not completed and the tool does not automatically replay |
| Media creation timeout | Check logs and existing tasks to avoid repeated creation |
Long task design
Distinguish between connection timeout, streaming idle timeout and total business deadline. Save IDs for media tasks to separate queries from user page waits; closing the page does not cancel the task. The number of retries, SDK default behavior, and background task recovery should all have the same budget.