Skip to content

Conversation

@petyosi
Copy link
Contributor

@petyosi petyosi commented Nov 10, 2025

We keep the prices in memory, I believe this should be good enough for a worker? Auto-updating every 30 minutes, as Samuel suggested. The update is non-blocking.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements automatic price data updates for the AI gateway by introducing a new price auto-update mechanism that fetches and caches provider pricing data from the @pydantic/genai-prices package.

  • Adds a new setupPriceAutoUpdate module with TTL-based caching (30-minute refresh interval)
  • Integrates the price update setup into the main request handler
  • Implements concurrent fetch prevention and stale data handling logic

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
gateway/src/setupPriceAutoUpdate.ts New module implementing price data auto-update with caching, TTL management, and integration with the genai-prices package
gateway/src/index.ts Integrates price auto-update by calling setupPriceAutoUpdate at the start of each gateway request

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@alexmojaki
Copy link

Personally, I think this is unnecessary, as this will tax one unlucky request every 30 minutes.

I think it should be running in the background and the calculation should be using whatever latest data is already present. That data should be replaced independently.

@petyosi petyosi force-pushed the petyo/setup-genai-price-auto-update branch 2 times, most recently from 4c3f4ac to dab2252 Compare November 10, 2025 12:13
@petyosi petyosi requested a review from Copilot November 10, 2025 12:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@petyosi petyosi force-pushed the petyo/setup-genai-price-auto-update branch from 9a958f1 to eb84677 Compare November 10, 2025 12:25
@petyosi petyosi marked this pull request as ready for review November 10, 2025 16:25
@petyosi petyosi requested a review from Kludex November 11, 2025 07:50
ctx: ExecutionContext,
options: GatewayOptions,
): Promise<Response> {
ctx.waitUntil(refreshGenaiPrices())
Copy link

@alexmojaki alexmojaki Nov 11, 2025

Choose a reason for hiding this comment

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

I'm confused how this is non-blocking. refreshGenaiPrices() returns waitForUpdate() which returns providerDataPromise which should be freshDataPromise.

@petyosi petyosi merged commit 76a6ed0 into main Nov 13, 2025
3 checks passed
@petyosi petyosi deleted the petyo/setup-genai-price-auto-update branch November 13, 2025 06:58
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