Fix OpenAI response created timestamp (#16401)

## What this fixes

Closes #16400.

`get_data_openai()` currently returns `created: null` when callers do
not pass a timestamp, and it replaces explicit timestamp values with the
current time. This makes non-streaming OpenAI-compatible responses
inconsistent with the expected integer `created` timestamp field.

## Change

- Preserve explicit `created` values when provided.
- Default non-streaming responses to `int(time.time())` when `created`
is not provided.
- Add focused unit coverage for default timestamps, explicit timestamps,
and unchanged streaming chunk shape.

## Verification

- `./.venv/bin/python -m pytest
test/unit_test/api/utils/test_api_utils.py -q`
- `python3 -m py_compile api/utils/api_utils.py
test/unit_test/api/utils/test_api_utils.py`
- `uvx ruff check api/utils/api_utils.py
test/unit_test/api/utils/test_api_utils.py`

---------

Co-authored-by: Harsh Kashyap <harshkashyap@Harshs-MacBook-Pro.local>
This commit is contained in:
Harsh Kashyap
2026-07-06 11:46:16 +05:30
committed by GitHub
parent b633ff0435
commit 98189cd20a
2 changed files with 49 additions and 1 deletions

View File

@@ -444,7 +444,7 @@ def get_data_openai(id=None, created=None, model=None, prompt_tokens=0, completi
return {
"id": f"{id}",
"object": object,
"created": int(time.time()) if created else None,
"created": created if created is not None else int(time.time()),
"model": model,
"param": param,
"usage": {