Skip to main content

Custom Providers

Alchemy allows you to create custom resource providers for any cloud service or API. This guide shows you how to implement custom resources following Alchemy’s conventions and patterns.

Resource Structure

A custom resource consists of three parts:
  1. Props Interface - Input configuration
  2. Output Type - Resource attributes after creation
  3. Resource Implementation - Lifecycle management (create, update, delete)

Creating a Basic Resource

Step 1: Define Interfaces

Step 2: Implement Resource Lifecycle

Step 3: Add Type Guard

Advanced Patterns

Input Normalization

For resources accepting flexible input types (e.g., string | Secret), use a wrapper function:

Resource Replacement

Handle immutable properties with resource replacement:

Conditional Deletion

Support opt-out deletion for data resources:
Only use conditional deletion for data resources (databases, storage). Always delete compute resources (workers, functions).

Local Development Support

Support local development mode:

Retry with Exponential Backoff

Handle transient errors:

API Client Pattern

Create a reusable API client:

Type Patterns

Flat Properties

Prefer flat properties over nested objects:

Omit Pattern for Outputs

Internal Types

Mark internal API types:

Testing Custom Resources

Write comprehensive tests:

Best Practices

Complete Example

Here’s a complete custom resource implementation:

Next Steps