Web APIs for Getting the Most Out of AI

author-image

By

While AI makes many tasks easier for developers, it can also introduce new challenges, such as how to leverage the full power of a device's hardware to execute complex AI models efficiently within a web browser. Intel is addressing these challenges by contributing to APIs that help bridge the gap between hardware and applications to make AI more accessible and performant across diverse web platforms. 

With the Web Neural Network (WebNN) and WebGPU APIs, for example, we've enabled developers to run powerful image recognition models directly in the browser and smoothly render complex 3D visualizations by leveraging the GPU for AI calculations. 

An introduction to WebNN with bullet points highlighting key features.

Figure 1: WebNN allows developers more direct access to hardware features designed to optimize software performance.

In this article, we look at the new APIs and standards shaping how you work with the Web. But first, let’s start by answering the question: why now?

Shifting AI to the Client Side

Before the meteoric rise of ChatGPT, AI had traditionally been the domain of data centers, where powerful servers manage the intensive workloads required for training and inference. This approach, while effective, comes with excessive costs—building and maintaining these huge data centers costs millions—as well as privacy and regulatory concerns, such as the potential for sensitive data breaches.

As AI has become more mainstream, issues around cost, speed, and security have created a shift toward processing AI workloads locally on devices. From a financial standpoint, running AI inference locally reduces the need for building and maintaining large, expensive data centers or renting time on them. And processing data closer to the source minimizes latency, leading to faster and more responsive applications while also mitigating the risk of non-compliance with data residency laws that require data to be stored within certain geographical boundaries for security and privacy reasons.

Web and AI: Bridging the Gap

To support a more flexible model where client devices can also participate in the execution of AI inferences, Intel introduced the AI PC—a new generation of PCs equipped with hardware specifically designed to run AI workloads. The AI PC leverages CPUs for general-purpose processing, GPUs for large throughput-oriented models, and NPUs for sustained, power-efficient AI use cases.

A slide introducing the AI PC with boxes providing definitions for GPU, NPU, and CPU.

Figure 2: The AI PC relies on GPUs, NPUs, and CPUs to handle AI tasks locally and more efficiently.

But hardware is only as effective as the software that runs on it. The web's ability to deliver consistent experiences across devices and operating systems makes it an ideal platform for deploying AI capabilities. Web developers can create applications that run seamlessly on a variety of devices, from desktops to smartphones, without the need for separate versions for each platform.  

It Takes a Village

Enter Project Fugu, a collaboration between companies including Intel, Google, Microsoft, and Samsung to bridge the gap between native applications and the web. The collaboration aims to create new APIs and standards to integrate AI capabilities within the web and enable web applications to access advanced hardware capabilities, such as GPU acceleration, real-time video processing, and machine learning inference.

Here are just a few examples that illustrate how advanced hardware capabilities and AI are starting to become integrated into web applications, enhancing their performance and user experience:
 

  1. Background Blurring: Check out a real-time background blurring demo and an example of how to use TensorFlow to remove the background of a video chat.
  2. Face Detection: You can see face detection in action using the Face-api.js JavaScript library, which implements face detection, recognition, and landmark detection using TensorFlow.js​​.
  3. Visual Studio Code in the browser: Explore how VS Code runs directly in the browser with the help of the File System Access API.
  4. Photoshop in the browser: Adobe also offers a web-based version of Photoshop, offering a glimpse into how advanced applications can leverage web technologies.

Screen capture of Visual Studio Code for the web that highlights that the tool was made possible with the File System Access API.

Figure 3: The web-based version of Visual Studio Code, made possible with the File System Access API.

Security First Approach

As new APIs emerge, ensuring privacy and security is critical to establishing trust with users. Transparency is key. Users require proper control of their data, and a clear understanding of what APIs can do, or they risk exposing sensitive information, potentially leading to privacy breaches, such as unauthorized data sharing or manipulation through APIs that access personal files without clear permission. These breaches can erode trust, deter the use of web services, and halt technological advancement, while also posing risks like identity theft and financial loss, underscoring the importance of robust privacy safeguards.

It's in the best interest of industry leaders, like Intel, to work proactively to ensure privacy and security in API development, which is exemplified by the File System Access API’s restrictions limiting access to certain directories and requiring explicit user prompts. This approach is part of Intel's strategy to emphasize user consent and data protection. Intel also collaborates with the open source community and W3C members to establish standards and best practices that further reinforce user privacy and security.   

Web APIs for AI

New web APIs significantly enhance the integration of AI into web applications by optimizing performance, providing high-level graphics and compute capabilities, and enabling machine learning across various devices. Here’s a look at a few key APIs driving this innovation:

 

  • WebAssembly allows code written in multiple languages to run on the web at near-native speed by compiling code into a low-level binary format. Developers can build high-performance web applications that were previously only feasible as native applications, making WebAssembly crucial for applications requiring intensive computations and quick execution times.
  • WebGPU provides high-performance graphics and compute capabilities essential for tasks such as 3D rendering, data visualization, and complex simulations. It allows developers to harness the full power of modern GPUs directly from the web, enabling smoother graphics and faster processing. WebGPU benefits applications that demand high graphical fidelity and real-time interactions.
  • The Web Neural Network API (WebNN) enables machine learning across CPUs, GPUs, and NPUs. Developers can specify the device type and power preference to achieve optimal performance for AI tasks. WebNN facilitates the development of machine learning models directly in the browser, making AI more accessible and efficient for web developers.
  • The Compute Pressure API monitors system compute resource availability, allowing applications to adapt their behavior based on the current load. This API provides real-time feedback on system resource usage, helping developers optimize their applications for better performance and responsiveness, especially in environments with varying compute loads.

Icons and brief descriptions of four new Web APIs: WebAssembly, WebGPU, WebNN, and Compute Pressure.

Figure 4: An overview of four key new Web APIs.

These new web APIs are transforming how developers integrate AI into web applications, making the applications more powerful, efficient, and responsive. Leveraging tools like WebAssembly, WebGPU, WebNN, and the Compute Pressure API, developers can push the boundaries of what’s possible on the web, creating seamless and advanced user experiences.
 

If you want to play around with AI on the web and see what you can do with some of these APIs, you should check out Intel’s Web AI showcase. Here, you’ll find examples and demos that you can filter by API, such as WebGPU or WebNN, or by device type (CPU, GPU, or NPU). You can also see which higher level framework has been used, like transformer.js, for example.

Give It a Try

The integration of AI into personal computing and the web is not just a technological advancement; it’s a transformative shift that enhances performance, privacy, and user experience for everyone. Now’s the time to get involved. Start by downloading the developer preview of your favorite browser and experimenting with some of the APIs mentioned and linked to in this article. Then, share your feedback, get involved with a project, and join us in pioneering the next generation of web experiences.

A browser showing the WebNN Developer Preview.

Figure 5: Try experimenting in a web browser’s developer preview to explore new web APIs like WebNN.

Additional Resources For Curious Minds
 

About the Author

Kenneth Rohde Christiansen is an Intel principal software engineer and architect specializing in mobile technology and web browsers. He plays a pivotal role in defining Intel's web platform strategy. Kenneth's expertise extends to projects related to progressive web apps (PWAs) and native capabilities, including his active involvement in Project Fugu, with a strong focus on artificial intelligence and modern hardware capabilities. Before joining Intel, Kenneth made significant contributions while at Nokia, working on projects such as the Nokia N9 web browser, Qt, and WebKit. His expertise and experience led to his election as a W3C Technical Architecture Group (TAG) member.