Skip to content

[functions] Add optimizeImageFromBytes and optimizeImageFromUrl - #17263

Draft
falcoagustin wants to merge 2 commits into
mainfrom
falcoagustin/functions-image-optimization
Draft

[functions] Add optimizeImageFromBytes and optimizeImageFromUrl#17263
falcoagustin wants to merge 2 commits into
mainfrom
falcoagustin/functions-image-optimization

Conversation

@falcoagustin

Copy link
Copy Markdown
Contributor

Why

Unlock agentic image optimization for code that isn't tied to a deployment's next/image config (AI Gateway outputs, blob workflows, functions optimizing arbitrary images). This is the Functions milestone of the standalone image-optimization API design:

import { optimizeImageFromBytes, optimizeImageFromUrl } from '@vercel/functions';

const { data } = await optimizeImageFromBytes(bytes, { width: 512, quality: 75, format: 'webp' });
const { data } = await optimizeImageFromUrl('https://me.com/logo.png', { width: 512, format: 'webp' });
  • Calls 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's project_id claim, and the API enforces the token↔project binding server-side.
  • Because @vercel/oidc also resolves tokens outside Vercel workloads (vercel env pull, CLI-based refresh), these methods work locally and in CI, not just inside functions.
  • optimizeImageFromBytes supports optional contentType and fileName (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-api flag, 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

  • 7 unit tests covering query/header/body shaping for both methods, OIDC bearer forwarding, quality default, ArrayBuffer input, missing project_id claim, upstream error surfacing, and the API URL override used for testing.

🤖 Generated with Claude Code

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-bot

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cfa7f47

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@vercel/oidc Minor
@vercel/functions Minor
@vercel/connect Patch
@vercel/oidc-aws-credentials-provider Patch
@vercel/aws Patch

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

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

🧪 Unit Test Strategy

Comparing: c6ed10acfa7f47 (view diff)

Strategy: Affected packages only

✅ Only testing packages that have been modified or depend on modified packages.

Affected packages - 15 (31%)
  1. @vercel/aws
  2. @vercel/connect
  3. @vercel/edge
  4. @vercel/elysia
  5. @vercel/express
  6. @vercel/fastify
  7. @vercel/functions
  8. @vercel/h3
  9. @vercel/hono
  10. @vercel/koa
  11. @vercel/nestjs
  12. @vercel/node
  13. @vercel/oidc
  14. @vercel/oidc-aws-credentials-provider
  15. vercel
Unaffected packages - 34 (69%)
  1. @vercel-internals/get-package-json
  2. @vercel-internals/ipc-proxy
  3. @vercel/backends
  4. @vercel/build-utils
  5. @vercel/cervel
  6. @vercel/cli-auth
  7. @vercel/cli-config
  8. @vercel/cli-exec
  9. @vercel/client
  10. @vercel/config
  11. @vercel/container
  12. @vercel/detect-agent
  13. @vercel/error-utils
  14. @vercel/firewall
  15. @vercel/frameworks
  16. @vercel/fs-detectors
  17. @vercel/gatsby-plugin-vercel-analytics
  18. @vercel/gatsby-plugin-vercel-builder
  19. @vercel/go
  20. @vercel/hydrogen
  21. @vercel/next
  22. @vercel/passport
  23. @vercel/python
  24. @vercel/python-analysis
  25. @vercel/redwood
  26. @vercel/related-projects
  27. @vercel/remix-builder
  28. @vercel/routing-utils
  29. @vercel/ruby
  30. @vercel/rust
  31. @vercel/static-build
  32. @vercel/static-config
  33. @vercel/vc-native
  34. examples

Results

  • Unit tests: Only affected packages will run unit tests
  • E2E tests: Running in parallel in this workflow
  • Type checks: Only affected packages will run type checks

This comment is automatically generated based on the affected testing strategy

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

📦 CLI Tarball Ready

The Vercel CLI tarball for this PR is now available!

Quick Test

You can test this PR's CLI directly by running:

npx https://vercel-7bvnakfhf.vercel.sh/tarballs/vercel.tgz --help

Use in vercel.json

To use this CLI version in your project builds, add to your vercel.json:

{
  "build": {
    "env": {
      "VERCEL_CLI_VERSION": "vercel@https://vercel-7bvnakfhf.vercel.sh/tarballs/vercel.tgz"
    }
  }
}

Python Runtime Wheel

A vercel-runtime wheel was also built for this PR.
To use in your Python project builds, also set this environment variable:

VERCEL_RUNTIME_PYTHON="vercel-runtime @ https://vercel-7bvnakfhf.vercel.sh/tarballs/vercel_runtime-0.17.0.dev1785241291+cfa7f47-py3-none-any.whl"

Python Workers Wheel

A vercel-workers wheel was also built for this PR.
To use in your Python project builds, also set this environment variable:

VERCEL_WORKERS_PYTHON="vercel-workers @ https://vercel-7bvnakfhf.vercel.sh/tarballs/vercel_workers-0.1.0.dev1785241291+cfa7f47-py3-none-any.whl"

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>
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.

1 participant