[functions] Add optimizeImageFromBytes and optimizeImageFromUrl - #17263
[functions] Add optimizeImageFromBytes and optimizeImageFromUrl#17263falcoagustin wants to merge 2 commits into
Conversation
Expose Vercel Image Optimization as SDK methods that call the api.vercel.com image-optimization endpoints, authenticating with the ambient Vercel OIDC token (via @vercel/oidc, so this also works outside Vercel workloads wherever a token is available, e.g. `vercel env pull` or CLI-based refresh). The target project is derived from the token's project_id claim, so no configuration is needed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: cfa7f47 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🧪 Unit Test StrategyComparing: Strategy: Affected packages only ✅ Only testing packages that have been modified or depend on modified packages. Affected packages - 15 (31%)
Unaffected packages - 34 (69%)
Results
This comment is automatically generated based on the affected testing strategy |
📦 CLI Tarball ReadyThe Vercel CLI tarball for this PR is now available! Quick TestYou can test this PR's CLI directly by running: npx https://vercel-7bvnakfhf.vercel.sh/tarballs/vercel.tgz --helpUse in vercel.jsonTo use this CLI version in your project builds, add to your {
"build": {
"env": {
"VERCEL_CLI_VERSION": "vercel@https://vercel-7bvnakfhf.vercel.sh/tarballs/vercel.tgz"
}
}
}Python Runtime WheelA Python Workers WheelA This comment is automatically generated |
Move the unverified JWT payload decode from token-util into a runtime-agnostic token-payload module (Buffer with atob fallback), export it from the node, edge-light, and browser entrypoints, and type the Vercel claims (project_id, owner_id, environment). The functions image-optimization module now delegates claim decoding to @vercel/oidc instead of hand-rolling base64url parsing. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Why
Unlock agentic image optimization for code that isn't tied to a deployment's
next/imageconfig (AI Gateway outputs, blob workflows, functions optimizing arbitrary images). This is the Functions milestone of the standalone image-optimization API design:POST api.vercel.com/v1/projects/:id/image-optimization/optimize-from-{bytes,url}authenticated with the ambient Vercel OIDC token via@vercel/oidc— zero configuration; the target project comes from the token'sproject_idclaim, and the API enforces the token↔project binding server-side.@vercel/oidcalso resolves tokens outside Vercel workloads (vercel env pull, CLI-based refresh), these methods work locally and in CI, not just inside functions.optimizeImageFromBytessupports optionalcontentTypeandfileName(forwarded for usage-fact attribution); bytes capped at 5MB by the API.Dependencies / rollout
The API endpoints are private, gated by the
enable-image-optimization-apiflag, and roll out via vercel/api#82465 (URL mode) → vercel/proxy#22438 (bytes upstream) → vercel/api#82432 (bytes mode). This SDK change is safe to land independently — calls simply 404 until a team is flag-enabled.Validation
project_idclaim, upstream error surfacing, and the API URL override used for testing.🤖 Generated with Claude Code