Skip to main content

GrainConfig Interface

All available configuration options when creating a Grain client:

Required Options

tenantId

Your unique tenant identifier from Grain. Use the alias shown on your dashboard (not the UUID). Get this from grainql.com/dashboard.

Authentication Options

authStrategy

Choose your authentication method:
  • 'NONE' - No authentication (default)
  • 'SERVER_SIDE' - Secret key authentication
  • 'JWT' - JSON Web Token authentication

secretKey

Required for SERVER_SIDE authentication. Never expose in client code.

authProvider

Required for JWT authentication. Provides tokens for requests.

User Options

userId

Global user ID for all events. Can be changed with setUserId().

API Options

apiUrl

Custom API endpoint. Defaults to https://clientapis.grainql.com.
Useful for self-hosted or region-specific deployments.

Batching Options

batchSize

Number of events to accumulate before sending. Default: 50.
Larger batches = fewer requests but longer delays.

flushInterval

Milliseconds between automatic flushes. Default: 5000 (5 seconds).
Set to 0 to disable automatic flushing (manual only).

Retry Options

retryAttempts

Number of retry attempts for failed requests. Default: 3.

retryDelay

Base delay in milliseconds between retries. Uses exponential backoff. Default: 1000 (1 second).

Remote Config Options

defaultConfigurations

Default values for configurations. Returns immediately, no API call needed.
Always provide defaults for critical configs.

configCacheKey

Custom key for localStorage cache. Default: 'grain_config'.
Useful if running multiple Grain instances.

configRefreshInterval

Milliseconds between automatic config refreshes. Default: 300000 (5 minutes).
Set to 0 to disable automatic refreshing.

enableConfigCache

Enable/disable configuration caching. Default: true.
Disable for testing or when cache causes issues.

Debug Options

debug

Enable console logging for debugging. Default: false.
Logs batching, sending, responses, and errors. Disable in production.

Environment-Specific Configs

Adjust config based on environment:

Performance Tuning

High-traffic apps:
Real-time apps:
Serverless functions:

Next Steps

Performance

Optimize for your use case

Error Handling

Handle errors gracefully