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.
This TypeScript code example sends an HTTP POST to the https://hcti.io/v1/image API. Converting your HTML/CSS to an image with TypeScript.
This example uses the axios package. Install with npm install axios.
importaxiosfrom'axios';interfaceImageRequest{html:string;css?:string;google_fonts?:string;}interfaceImageResponse{url:string;}asyncfunctioncreateImage():Promise<string>{constpayload:ImageRequest={html:"<div class='box'>TypeScript ✅</div>",css:".box { border: 4px solid #03B875; padding: 20px; font-family: 'Roboto'; }",google_fonts:"Roboto"};// Retrieve your api_id and api_key from the Dashboard. https://htmlcsstoimage.com/dashboardconstresponse=awaitaxios.post<ImageResponse>('https://hcti.io/v1/image',payload,{auth:{username:'your-user-id',password:'your-api-key'},headers:{'Content-Type':'application/json'}});returnresponse.data.url;}createImage().then(url=>console.log(url)).catch(error=>console.error(error));// https://hcti.io/v1/image/1113184e-419f-49f1-b231-2069942a186f
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 [email protected] with any questions and we’ll gladly help you get started.