A Node.js client library for the RenderCAD AI API. Transform flat images into photorealistic renders via a simple API.
npm install rendercad-aiFor Node.js versions below 18, you'll need to install node-fetch:
npm install rendercad-ai node-fetchconst RenderCADClient = require('rendercad-ai');
// Initialize client with your API token
const client = new RenderCADClient('YOUR_API_TOKEN');
// Render an image
const result = await client.renderImage('./image.jpg');
console.log('Job ID:', result.job_id);
// Check status
const status = await client.checkStatus(result.job_id);
console.log('Status:', status.status);
if (status.status === 'completed') {
console.log('Output URL:', status.output_url);
}Get your API token from: Account Settings → API Tokens → Generate New Token
const client = new RenderCADClient('YOUR_API_TOKEN');For desktop apps, browser extensions, and CLI tools:
const client = new RenderCADClient();
// Step 1: Request device code
const deviceCode = await client.requestDeviceCode({
app_name: 'My Desktop App',
app_type: 'desktop-app',
app_version: '1.0.0'
});
console.log('Code:', deviceCode.code);
console.log('Visit:', deviceCode.verification_url);
// Step 2: Poll for authorization
const checkAuth = async () => {
const result = await client.pollDeviceCode(deviceCode.code);
if (result.status === 'authorized') {
client.setApiToken(result.api_token);
console.log('Authorized!');
} else {
// Wait and poll again
setTimeout(checkAuth, deviceCode.poll_interval * 1000);
}
};
checkAuth();new RenderCADClient(apiToken, options)apiToken(string, optional): Your API tokenoptions(object, optional):baseUrl(string): Base URL for the API (default:'https://rendercad.ai')
Submit an image for rendering.
Parameters:
image(Buffer | string): Image buffer, file path, or base64 data URL
Returns: Promise resolving to { success: true, job_id: string }
Example:
// Using file path
const result = await client.renderImage('./image.jpg');
// Using Buffer
const fs = require('fs');
const buffer = fs.readFileSync('image.jpg');
const result = await client.renderImage(buffer);
// Using base64 string
const result = await client.renderImage('data:image/jpeg;base64,/9j/4AAQ...');Check the status of a render job.
Parameters:
jobId(string): Job ID fromrenderImageresponse
Returns: Promise resolving to:
{
success: true,
status: 'pending' | 'processing' | 'completed' | 'failed',
output_url?: string // Present when status is 'completed'
}Example:
const status = await client.checkStatus('render_68f59c4d873762.99760761');Get account information and usage statistics.
Returns: Promise resolving to:
{
success: true,
user: {
monthly_render_limit: number,
monthly_renders_used: number
}
}Example:
const account = await client.checkAccount();
console.log(`Used ${account.user.monthly_renders_used} of ${account.user.monthly_render_limit} renders`);Request a device code for OAuth-style authentication.
Parameters:
options(object, optional):app_name(string): Application nameapp_type(string):'browser-extension','desktop-app','mobile-app', or'cli-tool'app_version(string): Application version
Returns: Promise resolving to:
{
success: true,
code: string,
expires_in: number,
poll_interval: number,
verification_url: string
}Poll for device code authorization.
Parameters:
code(string): Device code fromrequestDeviceCode
Returns: Promise resolving to:
{
status: 'pending' | 'authorized',
api_token?: string // Present when status is 'authorized'
}Set or update the API token.
Parameters:
token(string): API token
The client throws custom error classes for different HTTP status codes:
const {
RenderCADError,
BadRequestError, // 400
UnauthorizedError, // 401
NotFoundError, // 404
RateLimitError, // 429
ServerError, // 500
} = require('rendercad-ai/src/errors');
try {
await client.renderImage('./image.jpg');
} catch (error) {
if (error instanceof RateLimitError) {
console.log('Monthly limit exceeded');
} else if (error instanceof UnauthorizedError) {
console.log('Invalid API token');
} else {
console.log('Error:', error.message);
}
}const RenderCADClient = require('rendercad-ai');
const fs = require('fs');
async function renderExample() {
const client = new RenderCADClient('YOUR_API_TOKEN');
try {
// Check account
const account = await client.checkAccount();
console.log(`Account: ${account.user.monthly_renders_used}/${account.user.monthly_render_limit} renders used`);
// Render image
const result = await client.renderImage('./input.jpg');
console.log('Job ID:', result.job_id);
// Poll for completion
let status;
do {
await new Promise(resolve => setTimeout(resolve, 3000)); // Wait 3 seconds
status = await client.checkStatus(result.job_id);
console.log('Status:', status.status);
} while (status.status === 'pending' || status.status === 'processing');
if (status.status === 'completed') {
console.log('Render complete! Output URL:', status.output_url);
} else {
console.log('Render failed');
}
} catch (error) {
console.error('Error:', error.message);
}
}
renderExample();- Formats: JPEG, PNG, GIF, WebP
- Max size: 10MB
- Encoding: Automatically handled by the client (base64 with data URL prefix)
- Monthly token limits based on your plan
- Each render consumes 1 token
- API blocked when token limit exceeded
- Usage resets monthly
MIT