GeezerVison is showing github.com — feat(ai): add gateway evaluation providers by rekram1-node · Pull Request #50665 · anomalyco/opencode
Conversation
Summary
- add
OpenRouter.experimental.evaluation(...) through OpenRouter's System One endpoint
- add
VercelAIGateway.experimental.evaluation(...) through Vercel's provider-neutral /v1/evaluate endpoint
- type gateway-specific request options and preserve routing, generation, provider, usage, and cost metadata
- retain TypeSafe and Zen behavior while making the shared System One model generic over request options
- add a live OpenRouter cassette plus deterministic Vercel request/response coverage
Cloudflare AI Gateway is intentionally not included: its current “Evaluations” feature evaluates stored log datasets in the dashboard and does not expose the runtime typed-question model API implemented here.
Usage
OpenRouter
import { Effect } from "effect"
import { Evaluation, EvaluationClient } from "@opencode/ai/experimental"
import { OpenRouter } from "@opencode/ai/providers"
const model = OpenRouter.configure().experimental.evaluation("typesafe/jev-1.13")
const program = Evaluation.run({
model,
state: "I was charged twice. Please refund the duplicate payment.",
questions: {
refund: {
type: "boolean",
instructions: "Is the customer asking for a refund?",
},
},
options: {
provider: { zdr: true },
session_id: "support-session-1",
user: "customer-1",
},
})
const result = await Effect.runPromise(
program.pipe(Effect.provide(EvaluationClient.fetchLayer)),
)
result.answers.refund.probability // number, P(true)
result.providerMetadata?.openrouter?.responseId
result.usage?.providerMetadata?.openrouter?.cost
Vercel AI Gateway
import { Effect } from "effect"
import { Evaluation, EvaluationClient } from "@opencode/ai/experimental"
import { VercelAIGateway } from "@opencode/ai/providers"
const model = VercelAIGateway.configure().experimental.evaluation("typesafe-ai/jev")
const program = Evaluation.run({
model,
state: "The support agent issued a full refund.",
questions: {
refunded: {
type: "boolean",
instructions: "Was a refund issued?",
},
},
options: {
gateway: {
zeroDataRetention: true,
only: ["typesafe-ai"],
},
},
})
const result = await Effect.runPromise(
program.pipe(Effect.provide(EvaluationClient.fetchLayer)),
)
result.answers.refunded.probability
result.providerMetadata?.gateway?.generationId
OpenRouter resolves OPENROUTER_API_KEY. Vercel resolves AI_GATEWAY_API_KEY, then VERCEL_OIDC_TOKEN; both also accept explicit apiKey or auth configuration.
Verification
bun run check
bun typecheck from packages/ai
bun test from packages/ai (1,410 passed, 28 skipped)
- live OpenRouter
typesafe/jev-1.13 cassette replay
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|