Skip to content

fix: adds created timestamp for openai text completions - #5407

Merged
akshaydeo merged 2 commits into
devfrom
07-21-fix_adds_created_timestamp_for_openai_text_completions
Jul 21, 2026
Merged

akshaydeo merged 2 commits into
devfrom
07-21-fix_adds_created_timestamp_for_openai_text_completions

Conversation

@sammaji

@sammaji sammaji commented Jul 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds the missing created field to BifrostTextCompletionResponse to align with the OpenAI text completion response schema, and modernizes the ExtraParams type alias from map[string]interface{} to the equivalent map[string]any.

Changes

  • Added Created int field with omitempty to BifrostTextCompletionResponse, representing the Unix timestamp (in seconds) of when the completion was created — this field was previously absent from the struct despite being part of the API response.
  • Replaced map[string]interface{} with map[string]any in TextCompletionParameters.ExtraParams to use the modern Go type alias.

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

go version
go test ./...

Verify that text completion responses now include the created timestamp field when it is non-zero.

Screenshots/Recordings

N/A

Breaking changes

  • Yes
  • No

Related issues

N/A

Security considerations

None.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Text completion responses now expose optional creation timestamps, with OpenAI and Replicate streaming paths preserving timestamps through emitted chunks and schema conversions.

Changes

Text completion timestamp propagation

Layer / File(s) Summary
Update text completion schema contracts
core/schemas/textcompletions.go
Adds the optional Created Unix timestamp to responses and changes ExtraParams to map[string]any while preserving its excluded JSON behavior.
Preserve timestamps in response conversions
core/schemas/mux.go, core/providers/replicate/text.go
Populates Created when converting chat responses and Replicate responses to text completion responses.
Propagate timestamps through streaming responses
core/providers/utils/utils.go, core/providers/openai/openai.go, core/providers/replicate/replicate.go
Captures or parses provider timestamps and assigns them to streamed and terminal completion chunks.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: bearts, tejasghatte, akshaydeo

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and matches the main change: adding created timestamps for text completions, especially for OpenAI.
Description check ✅ Passed The description covers the required template sections and is mostly complete, including summary, changes, testing, and checklist items.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 07-21-fix_adds_created_timestamp_for_openai_text_completions

Comment @coderabbitai help to get the list of available commands.

sammaji commented Jul 21, 2026 •

Copy link
Copy Markdown
Member Author

@sammaji
sammaji marked this pull request as ready for review July 21, 2026 09:50
Copilot AI review requested due to automatic review settings July 21, 2026 09:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai
coderabbitai Bot requested a review from BearTS July 21, 2026 09:51
@greptile-apps

greptile-apps Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

This looks safe to merge.

  • The previously missing timestamp is now propagated through the identified conversion and streaming paths.
  • All callers of the updated response helper use the new signature.
  • No blocking issue was found in the changed code.

Important Files Changed

Filename Overview
core/providers/openai/openai.go Captures the stream creation timestamp and includes it in the final text completion response.
core/providers/replicate/replicate.go Adds the prediction creation timestamp to Replicate text completion stream responses.
core/providers/replicate/text.go Maps the Replicate prediction timestamp into unary text completion responses.
core/providers/utils/utils.go Extends the text completion response helper to accept and preserve a creation timestamp.
core/schemas/mux.go Copies creation timestamps through every chat-to-text conversion branch.
core/schemas/textcompletions.go Adds the created response field and updates the extra-parameter map alias.

Reviews (3): Last reviewed commit: "fix: adds created timestamp for openai t..." | Re-trigger Greptile

Comment thread core/schemas/textcompletions.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/schemas/textcompletions.go`:
- Line 70: Update the created field in the text-completion response schema to
remove omitempty so the required Unix timestamp is always serialized, preserving
the existing json field name and type.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d807a1df-2734-4f47-b936-30ed1871da03

📥 Commits

Reviewing files that changed from the base of the PR and between cba1d0f and 5ce7f0b.

📒 Files selected for processing (1)
  • core/schemas/textcompletions.go

Comment thread core/schemas/textcompletions.go
@sammaji
sammaji force-pushed the 07-21-fix_adds_created_timestamp_for_openai_text_completions branch from 5ce7f0b to 222cb4f Compare July 21, 2026 10:43
@coderabbitai
coderabbitai Bot requested review from TejasGhatte and akshaydeo July 21, 2026 10:44

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
core/providers/openai/openai.go (1)

697-715: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Capture Created before skipping empty-choice chunks.

The handler supports usage-only chunks, but it skips every response with no choices before the new capture block. If such a chunk carries the only non-zero Created value, the final chunk omits the timestamp. Move the capture above the empty-choice check and remove the duplicate block.

Proposed fix
+			if response.Created != 0 && created == 0 {
+				created = response.Created
+			}
+
 			// Skip empty responses or responses without choices
 			if len(response.Choices) == 0 {
 				continue
 			}
-
-			if response.Created != 0 && created == 0 {
-				created = response.Created
-			}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/openai/openai.go` around lines 697 - 715, Move the
response.Created capture logic in the streaming handler before the
len(response.Choices) == 0 early-continue, so usage-only chunks can populate
created; remove the later duplicate capture while leaving messageID and
choice/finish-reason handling unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@core/providers/openai/openai.go`:
- Around line 697-715: Move the response.Created capture logic in the streaming
handler before the len(response.Choices) == 0 early-continue, so usage-only
chunks can populate created; remove the later duplicate capture while leaving
messageID and choice/finish-reason handling unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 33b09e60-5b89-4daf-860a-0b40e5bee824

📥 Commits

Reviewing files that changed from the base of the PR and between 5ce7f0b and 222cb4f.

📒 Files selected for processing (6)
  • core/providers/openai/openai.go
  • core/providers/replicate/replicate.go
  • core/providers/replicate/text.go
  • core/providers/utils/utils.go
  • core/schemas/mux.go
  • core/schemas/textcompletions.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • core/schemas/textcompletions.go

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 21, 2026
@sammaji
sammaji changed the base branch from dev to graphite-base/5407 July 21, 2026 11:41
@sammaji
sammaji force-pushed the graphite-base/5407 branch from e288ecc to 0fa6e8a Compare July 21, 2026 11:41
@sammaji
sammaji force-pushed the 07-21-fix_adds_created_timestamp_for_openai_text_completions branch from 222cb4f to 0ca30c5 Compare July 21, 2026 11:41
@sammaji
sammaji changed the base branch from graphite-base/5407 to 07-08-chore_adds_docs_for_azure_model_router July 21, 2026 11:41

akshaydeo commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Merge activity

  • Jul 21, 2:59 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 21, 3:00 PM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo
akshaydeo changed the base branch from 07-08-chore_adds_docs_for_azure_model_router to graphite-base/5407 July 21, 2026 14:59
@akshaydeo
akshaydeo changed the base branch from graphite-base/5407 to dev July 21, 2026 14:59
@akshaydeo
akshaydeo dismissed coderabbitai[bot]’s stale review July 21, 2026 14:59

The base branch was changed.

@akshaydeo
akshaydeo merged commit d314892 into dev Jul 21, 2026
11 checks passed
@akshaydeo
akshaydeo deleted the 07-21-fix_adds_created_timestamp_for_openai_text_completions branch July 21, 2026 15:00
akshaydeo added a commit that referenced this pull request Jul 21, 2026
* chore: fix migration tests

* framework test fixes (#5421)

* chore: adds docs for azure model router (#5175)

## Summary

Adds a dedicated documentation page for the Azure Model Router provider, explaining how Bifrost automatically falls back to Chat Completions when a model-router deployment is targeted via the Responses API.

## Changes

- Added `docs/providers/supported-providers/azure-model-router.mdx` documenting the Azure model-router routing behavior, supported operations, a Mermaid flowchart illustrating the fallback logic, usage examples (REST and Go SDK), and known limitations.
- Registered the new page in `docs/docs.json` so it appears in the navigation between the Azure and Bedrock entries.

## Type of change

- [ ] Bug fix
- [ ] Feature
- [ ] Refactor
- [x] Documentation
- [ ] Chore/CI

## Affected areas

- [ ] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [x] Docs

## How to test

Navigate to the Azure Model Router page in the rendered docs and verify:
- The page appears in the sidebar between Azure and Bedrock.
- The Mermaid flowchart renders correctly.
- All code examples and notes display as expected.

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

## Security considerations

None. This is a documentation-only change with no impact on auth, secrets, or runtime behavior.

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [ ] I added/updated tests where appropriate
- [x] I updated documentation where needed
- [ ] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable

* fix: adds created timestamp for openai text completions (#5407)

## Summary

Adds the missing `created` field to `BifrostTextCompletionResponse` to align with the OpenAI text completion response schema, and modernizes the `ExtraParams` type alias from `map[string]interface{}` to the equivalent `map[string]any`.

## Changes

- Added `Created int` field with `omitempty` to `BifrostTextCompletionResponse`, representing the Unix timestamp (in seconds) of when the completion was created — this field was previously absent from the struct despite being part of the API response.
- Replaced `map[string]interface{}` with `map[string]any` in `TextCompletionParameters.ExtraParams` to use the modern Go type alias.

## Type of change

- [ ] Bug fix
- [ ] Feature
- [x] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [x] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

```sh
go version
go test ./...
```

Verify that text completion responses now include the `created` timestamp field when it is non-zero.

## Screenshots/Recordings

N/A

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

N/A

## Security considerations

None.

## Checklist

- [x] I read `docs/contributing/README.md` and followed the guidelines
- [x] I added/updated tests where appropriate
- [x] I updated documentation where needed
- [x] I verified builds succeed (Go and UI)
- [x] I verified the CI pipeline passes locally if applicable

---------

Co-authored-by: Samyabrata Maji <116789799+sammaji@users.noreply.github.com>
Co-authored-by: Samyabrata Maji <samyabratamaji334@gmail.com>
@coderabbitai coderabbitai Bot mentioned this pull request Jul 21, 2026
akhsaul pushed a commit to akhsaul/bifrost that referenced this pull request Aug 27, 2026
## Summary

Adds the missing `created` field to `BifrostTextCompletionResponse` to align with the OpenAI text completion response schema, and modernizes the `ExtraParams` type alias from `map[string]interface{}` to the equivalent `map[string]any`.

## Changes

- Added `Created int` field with `omitempty` to `BifrostTextCompletionResponse`, representing the Unix timestamp (in seconds) of when the completion was created — this field was previously absent from the struct despite being part of the API response.
- Replaced `map[string]interface{}` with `map[string]any` in `TextCompletionParameters.ExtraParams` to use the modern Go type alias.

## Type of change

- [ ] Bug fix
- [ ] Feature
- [x] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [x] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

```sh
go version
go test ./...
```

Verify that text completion responses now include the `created` timestamp field when it is non-zero.

## Screenshots/Recordings

N/A

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

N/A

## Security considerations

None.

## Checklist

- [x] I read `docs/contributing/README.md` and followed the guidelines
- [x] I added/updated tests where appropriate
- [x] I updated documentation where needed
- [x] I verified builds succeed (Go and UI)
- [x] I verified the CI pipeline passes locally if applicable
akhsaul pushed a commit to akhsaul/bifrost that referenced this pull request Aug 27, 2026
* chore: fix migration tests

* framework test fixes (maximhq#5421)

* chore: adds docs for azure model router (maximhq#5175)

## Summary

Adds a dedicated documentation page for the Azure Model Router provider, explaining how Bifrost automatically falls back to Chat Completions when a model-router deployment is targeted via the Responses API.

## Changes

- Added `docs/providers/supported-providers/azure-model-router.mdx` documenting the Azure model-router routing behavior, supported operations, a Mermaid flowchart illustrating the fallback logic, usage examples (REST and Go SDK), and known limitations.
- Registered the new page in `docs/docs.json` so it appears in the navigation between the Azure and Bedrock entries.

## Type of change

- [ ] Bug fix
- [ ] Feature
- [ ] Refactor
- [x] Documentation
- [ ] Chore/CI

## Affected areas

- [ ] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [x] Docs

## How to test

Navigate to the Azure Model Router page in the rendered docs and verify:
- The page appears in the sidebar between Azure and Bedrock.
- The Mermaid flowchart renders correctly.
- All code examples and notes display as expected.

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

## Security considerations

None. This is a documentation-only change with no impact on auth, secrets, or runtime behavior.

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [ ] I added/updated tests where appropriate
- [x] I updated documentation where needed
- [ ] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable

* fix: adds created timestamp for openai text completions (maximhq#5407)

## Summary

Adds the missing `created` field to `BifrostTextCompletionResponse` to align with the OpenAI text completion response schema, and modernizes the `ExtraParams` type alias from `map[string]interface{}` to the equivalent `map[string]any`.

## Changes

- Added `Created int` field with `omitempty` to `BifrostTextCompletionResponse`, representing the Unix timestamp (in seconds) of when the completion was created — this field was previously absent from the struct despite being part of the API response.
- Replaced `map[string]interface{}` with `map[string]any` in `TextCompletionParameters.ExtraParams` to use the modern Go type alias.

## Type of change

- [ ] Bug fix
- [ ] Feature
- [x] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [x] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

```sh
go version
go test ./...
```

Verify that text completion responses now include the `created` timestamp field when it is non-zero.

## Screenshots/Recordings

N/A

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

N/A

## Security considerations

None.

## Checklist

- [x] I read `docs/contributing/README.md` and followed the guidelines
- [x] I added/updated tests where appropriate
- [x] I updated documentation where needed
- [x] I verified builds succeed (Go and UI)
- [x] I verified the CI pipeline passes locally if applicable

---------

Co-authored-by: Samyabrata Maji <116789799+sammaji@users.noreply.github.com>
Co-authored-by: Samyabrata Maji <samyabratamaji334@gmail.com>
occcat pushed a commit to occcat/bifrost that referenced this pull request Sep 2, 2026
## Summary

Adds the missing `created` field to `BifrostTextCompletionResponse` to align with the OpenAI text completion response schema, and modernizes the `ExtraParams` type alias from `map[string]interface{}` to the equivalent `map[string]any`.

## Changes

- Added `Created int` field with `omitempty` to `BifrostTextCompletionResponse`, representing the Unix timestamp (in seconds) of when the completion was created — this field was previously absent from the struct despite being part of the API response.
- Replaced `map[string]interface{}` with `map[string]any` in `TextCompletionParameters.ExtraParams` to use the modern Go type alias.

## Type of change

- [ ] Bug fix
- [ ] Feature
- [x] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [x] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

```sh
go version
go test ./...
```

Verify that text completion responses now include the `created` timestamp field when it is non-zero.

## Screenshots/Recordings

N/A

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

N/A

## Security considerations

None.

## Checklist

- [x] I read `docs/contributing/README.md` and followed the guidelines
- [x] I added/updated tests where appropriate
- [x] I updated documentation where needed
- [x] I verified builds succeed (Go and UI)
- [x] I verified the CI pipeline passes locally if applicable
occcat pushed a commit to occcat/bifrost that referenced this pull request Sep 2, 2026
* chore: fix migration tests

* framework test fixes (maximhq#5421)

* chore: adds docs for azure model router (maximhq#5175)

## Summary

Adds a dedicated documentation page for the Azure Model Router provider, explaining how Bifrost automatically falls back to Chat Completions when a model-router deployment is targeted via the Responses API.

## Changes

- Added `docs/providers/supported-providers/azure-model-router.mdx` documenting the Azure model-router routing behavior, supported operations, a Mermaid flowchart illustrating the fallback logic, usage examples (REST and Go SDK), and known limitations.
- Registered the new page in `docs/docs.json` so it appears in the navigation between the Azure and Bedrock entries.

## Type of change

- [ ] Bug fix
- [ ] Feature
- [ ] Refactor
- [x] Documentation
- [ ] Chore/CI

## Affected areas

- [ ] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [x] Docs

## How to test

Navigate to the Azure Model Router page in the rendered docs and verify:
- The page appears in the sidebar between Azure and Bedrock.
- The Mermaid flowchart renders correctly.
- All code examples and notes display as expected.

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

## Security considerations

None. This is a documentation-only change with no impact on auth, secrets, or runtime behavior.

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [ ] I added/updated tests where appropriate
- [x] I updated documentation where needed
- [ ] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable

* fix: adds created timestamp for openai text completions (maximhq#5407)

## Summary

Adds the missing `created` field to `BifrostTextCompletionResponse` to align with the OpenAI text completion response schema, and modernizes the `ExtraParams` type alias from `map[string]interface{}` to the equivalent `map[string]any`.

## Changes

- Added `Created int` field with `omitempty` to `BifrostTextCompletionResponse`, representing the Unix timestamp (in seconds) of when the completion was created — this field was previously absent from the struct despite being part of the API response.
- Replaced `map[string]interface{}` with `map[string]any` in `TextCompletionParameters.ExtraParams` to use the modern Go type alias.

## Type of change

- [ ] Bug fix
- [ ] Feature
- [x] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [x] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

```sh
go version
go test ./...
```

Verify that text completion responses now include the `created` timestamp field when it is non-zero.

## Screenshots/Recordings

N/A

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

N/A

## Security considerations

None.

## Checklist

- [x] I read `docs/contributing/README.md` and followed the guidelines
- [x] I added/updated tests where appropriate
- [x] I updated documentation where needed
- [x] I verified builds succeed (Go and UI)
- [x] I verified the CI pipeline passes locally if applicable

---------

Co-authored-by: Samyabrata Maji <116789799+sammaji@users.noreply.github.com>
Co-authored-by: Samyabrata Maji <samyabratamaji334@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants