Skip to content

feat: add optional baseUrl and userAgent to Resend constructor#839

Open
xiaoyu2er wants to merge 3 commits intoresend:canaryfrom
xiaoyu2er:feat/resend-options-baseurl-useragent
Open

feat: add optional baseUrl and userAgent to Resend constructor#839
xiaoyu2er wants to merge 3 commits intoresend:canaryfrom
xiaoyu2er:feat/resend-options-baseurl-useragent

Conversation

@xiaoyu2er
Copy link
Contributor

@xiaoyu2er xiaoyu2er commented Feb 7, 2026

Summary

Add optional options to the Resend constructor so callers can override baseUrl and userAgent while keeping the existing default/env behavior.

Changes

  • ResendOptions: New optional interface with baseUrl?: string and userAgent?: string.
  • Constructor: new Resend(key?, options?) — when options.baseUrl / options.userAgent are provided, they override env and defaults.
  • Instance properties: resend.baseUrl and resend.userAgent (readonly) used for requests and headers.
  • Defaults: Existing logic preserved via getDefaultBaseUrl() and getDefaultUserAgent() (env RESEND_BASE_URL / RESEND_USER_AGENT then fallbacks).
  • Exports: ResendOptions exported from the package entry.

Usage

// Default (env or https://api.resend.com)
const resend = new Resend('re_xxx');

// Custom baseUrl and/or userAgent
const resend = new Resend('re_xxx', {
  baseUrl: 'https://eu.api.resend.com',
  userAgent: 'my-app/1.0',
});

Tests

  • src/resend.spec.ts: 10 tests for default values, options override, env override, and that requests use custom baseUrl and User-Agent.

Summary by cubic

Adds optional per-instance baseUrl and userAgent to Resend. Options override env vars and defaults, and are used in request URLs and headers.

  • New Features
    • Constructor: new Resend(key?, { baseUrl?, userAgent? })
    • Options override RESEND_BASE_URL and RESEND_USER_AGENT; else fall back to env/defaults
    • Readonly properties: resend.baseUrl and resend.userAgent
    • Export ResendOptions from the package entry

Written for commit bc6ce72. Summary will update on new commits.

- Add ResendOptions interface with optional baseUrl and userAgent
- Use instance properties this.baseUrl and this.userAgent (env/options fallback)
- Export ResendOptions from index
- Add resend.spec.ts with tests for options and env override

Co-authored-by: Cursor <cursoragent@cursor.com>
@xiaoyu2er xiaoyu2er requested a review from a team as a code owner February 7, 2026 18:50
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

@xiaoyu2er
Copy link
Contributor Author

could you take a look @cassiozen @gabrielmfern 🙏

@xiaoyu2er xiaoyu2er closed this Feb 8, 2026
@xiaoyu2er xiaoyu2er reopened this Feb 8, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 8, 2026

Open in StackBlitz

npm i https://pkg.pr.new/resend/resend-node/resend@839

commit: bc6ce72

@gabrielmfern
Copy link
Member

What values would be passing in for baseUrl though? That https://eu.api.resend.com url doesn't really exist, and I don't think there's any other popular API that is Resend compatible, right?

@xiaoyu2er
Copy link
Contributor Author

xiaoyu2er commented Feb 11, 2026

@gabrielmfern

We added the options parameter so you can configure the client in code instead of having to set RESEND_BASE_URL / RESEND_USER_AGENT in the environment. That gives:

  • Explicit configuration — All config lives where the client is created (new Resend(apiKey, { baseUrl, userAgent })), so it’s obvious what each instance uses. No need to remember or document which env vars must be set.
  • Easier testing — Tests can pass a mock base URL or custom user agent per test or per suite, without mutating process.env or cleaning it up. No env setup/teardown in tests.
  • Multiple clients — You can use different base URLs or user agents in the same process (e.g. prod vs staging, or different regions later) by creating multiple Resend instances with different options. With env-only config, you’d have to change env at runtime.
  • Library / embedded use — When Resend is used inside another app or library, the caller can pass options directly instead of requiring the host app to set env vars. The SDK doesn’t depend on “ambient” env.
  • Env still supported — If you prefer env (e.g. in serverless or Docker), RESEND_BASE_URL / RESEND_USER_AGENT still apply when you don’t pass options; explicit options override env, so both styles are supported.

So the benefit is: you can configure the client explicitly at the call site instead of relying on environment variables, which makes behavior clearer, testing simpler, and multi-instance / library use straightforward.

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.

2 participants