Your username is your User ID and your password is your API Key. Both of these are available from the dashboard. The TypeScript code sample demonstrates how to authenticate your request.
We recommend only using the API server-side. This is important because it keeps your API key secret. If you expose them in the browser, they can be used by anyone.
TypeScript example with Fetch API
Using the built-in Fetch API (available in Node.js 18+ and modern browsers).
For larger projects, you may want more comprehensive type definitions for the API.
// types.tsexportinterfaceHtmlCssToImageRequest{/** The HTML you want to render */html?:string;/** The CSS for your image */css?:string;/** The URL of a webpage to screenshot */url?:string;/** Google fonts to load (comma separated) */google_fonts?:string;/** Delay in milliseconds before capturing */ms_delay?:number;/** Device scale factor (1-3) */device_scale?:number;/** Whether to render the full page */full_screen?:boolean;/** CSS selector to screenshot */selector?:string;}exportinterfaceHtmlCssToImageResponse{url:string;}exportinterfaceHtmlCssToImageError{error:string;statusCode:number;message:string;}// api.tsimporttype{HtmlCssToImageRequest,HtmlCssToImageResponse}from'./types';exportclassHtmlCssToImageClient{privatereadonlybaseUrl='https://hcti.io/v1/image';privatereadonlyauthHeader:string;constructor(userId:string,apiKey:string){this.authHeader='Basic '+Buffer.from(`${userId}:${apiKey}`).toString('base64');}asynccreateImage(request:HtmlCssToImageRequest):Promise<HtmlCssToImageResponse>{constresponse=awaitfetch(this.baseUrl,{method:'POST',body:JSON.stringify(request),headers:{'Content-Type':'application/json','Authorization':this.authHeader}});if(!response.ok){consterror=awaitresponse.json();thrownewError(error.message||`Request failed with status ${response.status}`);}returnresponse.json()asPromise<HtmlCssToImageResponse>;}}// Usageconstclient=newHtmlCssToImageClient('your-user-id','your-api-key');constimage=awaitclient.createImage({html:"<div class='card'>Welcome!</div>",css:".card { padding: 20px; border-radius: 8px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; }",google_fonts:"Inter"});console.log(image.url);
URL to Image with TypeScript
Capture a screenshot of any webpage:
interfaceScreenshotRequest{url:string;full_screen?:boolean;ms_delay?:number;}asyncfunctionscreenshotUrl(request:ScreenshotRequest):Promise<string>{constresponse=awaitfetch('https://hcti.io/v1/image',{method:'POST',body:JSON.stringify(request),headers:{'Content-Type':'application/json','Authorization':'Basic '+Buffer.from('your-user-id:your-api-key').toString('base64')}});constdata=awaitresponse.json();returndata.url;}// Capture a full-page screenshotconstimageUrl=awaitscreenshotUrl({url:'https://htmlcsstoimage.com',full_screen:true,ms_delay:500});console.log(imageUrl);
Need help?
Talk to a human. Please email us support@htmlcsstoimage.com with any questions and we’ll gladly help you get started.