Add OpenRouter sample: prompt batch with cached retries - #520
Open
DABH wants to merge 2 commits into
Open
Conversation
Call OpenRouter from an Activity with the openai client pointed at OpenRouter, client retries off so Temporal owns every attempt, error classification with Retry-After as the next retry delay, heartbeats, and OpenRouter response caching so a retried identical request is billed at zero. The Workflow fans a prompt batch out under bounded concurrency and reports skipped prompts instead of failing the batch.
This was referenced Sep 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an
openroutersample: a Workflow that fans one Activity out per prompt through OpenRouter's Auto Router and returns answer, model, and reported cost per prompt.The Activity uses the
openaiclient pointed at OpenRouter withmaxRetries: 0, classifies 4xx as non-retryable and 408/429/5xx as retryable, passesRetry-Afterthrough asnextRetryDelay, heartbeats, checks for OpenRouter's 200-with-error body, and sendsX-OpenRouter-Cache: trueso a retried identical request is served from OpenRouter's cache at $0. A--fail-onceflag on the client demonstrates that; verified live with aHITat $0 on attempt 2.Tests use a fake
fetchand a fake Activity; no API key needed. Registered in the CI project list and the sample list. This is the TypeScript port of temporalio/samples-python#366 (prompt_batch); thebudget_gatescenario stays Python-only for now.