Add OpenRouter samples: prompt batch and budget gate - #366
Open
DABH wants to merge 1 commit into
Open
Conversation
Call OpenRouter from Activities with Temporal-owned retries, error classification, Retry-After handling, heartbeats, and OpenRouter response caching so a retried request is billed at zero. The budget_gate sample pauses the batch on a soft budget or on OpenRouter's 402 and resumes on a raise_budget Update. Also adds OpenRouter as a model provider for the OpenAI Agents SDK plugin sample.
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 with two scenarios, plus OpenRouter as a model provider for the OpenAI Agents SDK sample.prompt_batch fans one Activity out per prompt with OpenRouter's Auto Router and returns answer, model, and reported cost per prompt. The Activity uses the
openaiclient pointed at OpenRouter withmax_retries=0, classifies 4xx as non-retryable and 408/429/5xx as retryable, passesRetry-Afterthrough asnext_retry_delay, heartbeats, and sendsX-OpenRouter-Cache: trueso a retried identical request is served from OpenRouter's cache at $0. A--fail-onceflag demonstrates that.budget_gate is the same batch, but it pauses on a soft budget or on OpenRouter's 402 and resumes on a
raise_budgetUpdate, with aspend_reportQuery.Tests use
httpx.MockTransportand a fake Activity; no API key needed. Verified live against OpenRouter, including a cache hit at $0 on retry.Docs page: temporalio/documentation#5307. TypeScript port: temporalio/samples-typescript#520.