A Pi API - Happy Pi Day logo

100 Trillion Digits Edit

A computer screen with title "100 trillion digits :D" along with a pie with a banner of digits of pi

Records are made to be broken. In March 2022, we calculated 100 trillion digits of pi using Compute Engine. This is the second time we’ve used Google Cloud to calculate a record number of digits for the mathematical constant, tripling the number of digits in just three years after our world record with 31.4 trillion digits in 2019.

Check out the official blog for more details about the technical details and architecture of the calculation. And for more on the history of calculating pi, check out this post on The Keyword.

We’ve updated the API to serve all of the 100 trillion digits of pi. We’ve also published the entire results on Cloud Storage so you can download the files (caution: they are really big).

About this site Edit

This website serves pi and interactive demos that you can listen to or see pi with. Scroll down to play with the demos!

To learn more about how this site works, check out the Serving the Pi section. We’ve also published the entire source code of the demos and infrastructure, including Terraform scripts, on GitHub.

This website is not an official Google product. It is managed by volunteers of the Google Cloud Developer Advocacy team and may go down or shut down without notice.

Listen (Piano Genie) Edit

What does Pi sound like? Each Pi digit is converted to a musical note so you can get to know Pi via music!

Piano Genie is an neural network model that allows you to play a note from 1 to 8, and intelligently map it to a great sounding piano performance. In this demo, we use each digit for [0, 7] and reuse the last digit for [8, 9], and use Piano Genie to map to the next logical note for great sounding Pi.

With 100 trillion digits and playing at 314 BPM, it'll play for 605 516 years!

Listen (Bach Doodle) Edit

On March 21, 2019, Google presented Bach Doodle to celebrate world renowned German composer and musician Johann Sebastian Bach. You can create a melody line and use the AI to fill in the harmony. This demo uses Pi digits to create the melody, and then you can uses Google Bach Doodle ML model (Coconet) to infill the harmony. Coconet Javascript library is available as part of Magenta.JS. Learn more with Coconet demo and Coconet demo source.

This demo is turned off on mobile devices. Please use the latest desktop Chrome browser for the best experience.

An example image of the Coconet demo. There's a diagram at the top indicating notes generated by the machine learning engine. There's a control UI at the bottom with a slider and text field to select the digit, two checkboxes labeled as "Use machine learning" and "Loop play", and three buttons labeled as start, stop, and reset.

Visualize Edit

Visualize transitions from one digit to the next in Pi using D3.js. Each transition draws a line from a digit in the circle to another digit. Once you have a large amount of digits you can see which digits transition more often and which digits are more common.

Art Edit

For Google Cloud Next 2019 in San Francisco, a team created the Pi Experiment Showcase, and uses the Pi API & generative algorithm to generate unique art pieces for each of the 31.4 trillion digits of Pi.

Here is an art piece to the first 11 digits of e (2.7182818284): 27,182,818,284th digits of Pi

Learn more about the world record & generate your own unique art piece from the Pi Experiment Showcase.

/v1/pi Edit

Get Pi Digits

Returns digits of Pi based on the start digit position and numberOfDigits.

There is no SLA on this service. We may require an API key in the future & or turn off the service. This is not an official Google API.

We can use curl call the API from the command line.

curl 'https://api.pi.delivery/v1/pi?start=0&numberOfDigits=100'

Here’s an example to use the API in JavaScript.

  .then(response => response.json())
  .then(data => console.log(data));

The response looks like this.


The API also supports hexadecimal digits of pi. Use the radix parameter to specify the base.

curl 'https://api.pi.delivery/v1/pi?start=0&numberOfDigits=100&radix=16'

It will return a hexadecimal representation of pi.


Fetching Digits Edit

This demo uses the REST API to fetch 100 digits of Pi from the specified starting point. You can also try getting the hexadecimal digits of pi.

Serving the API Edit

We developed the REST API in Go and running the program in Cloud Functions (2nd gen).

The architecture looks like this:

Server architecture diagram. There's a Cloud Load Balancer in the front that redirects requests to Cloud Function instances in us-central1, europe-west1, asia-northeast1 regions. The functions connect to Cloud Storage in the US multi-region. Logging and Monitoring are used for monitoring. Cloud DNS is used for DNS resolutions.

We have the same function deployed in three regions (US, Belgium, Japan) that fetches digits from a Cloud Storage bucket in the US multi-region. The API endpoint, api.pi.delivery is exposed via a Global HTTP(s) Load Balancer. The authorative DNS servers are provided by Cloud DNS.

The frontend code is developed in TypeScript and React.

Finally, this site is hosted on Firebase Hosting, which not only automatically serves the static content via a CDN, it also automatically provisions a SSL certificate for the custom domain!

We have the entire source code published on GitHub including Terraform scripts that we use to provision the infrastructure.

Calculating Pi Edit

In 2022, Sara Ford and Ben Bleything calculated 64 million digits of π using Cloud Functions (2nd gen).

In 2019, Emma Haruka Iwao broke the Pi digits world record by computing 31,415,926,535,897 digits of Pi using Google Cloud Platform! Learn more details from Emma’s Calculating a record-breaking 31.4 trillion digits blog, and Alex Yee (creator of y-cruncher)’s Google Cloud Topples the Pi record article.

Back in 2017, we used y-cruncher to calculate 750 billion digits of Pi on Google Compute Engine. We used a 64-core instance, with 416GB of RAM, and tons of Local SSD + Persistent SSD.

At its peak CPU utilization, it consumed all 64 cores, and 5+TB of SSD storage.

In 2018, we were able to recalculate 750 billion digits in just 10 hours!

We also calculated 1 trillion digits of Pi using a 96-core 14TB n1-megamem-96 machine.

Who are We? Edit

We are part of the Google Cloud Platform Developer Advocacy team.

Since 2015, different members of the team worked on different Pi Day demos!

In 2022, Sara Ford and Ben Bleything calculated 64 million digits of π using Cloud Functions (2nd gen). Emma Haruka Iwao rebuilt the API with Cloud Functions and the demos with React. We also made the source code available on GitHub.

In 2020, we updated the Pi digits to 50 trillion digits, and added Machine Learning models to generate even better Pi music. e also had an opportunity to interview Timothy for Pi Day 2020. Check out this video if you want to hear two world record breakers discuss about pi!

In 2019, the Pi digits world record was broken by Emma Haruka Iwao. Google Cloud Experiment for Pi Day was created by Mathias Paumgarten. The Pi API was updated to serve all 31.4+ trillion digits by Ray Tsang.

In 2018, the Pi API was updated to serve 1 trillion digits by Ray Tsang.

In 2017, we made this site and the Pi API, by Francesc Campoy, Guillaume Laforge, Ian Lewis, Ray Tsang, Sandeep Dinesh.

In 2016, we calculated 500 billion digits of Pi and made it searchable. The indexing peaked at 2-million writes per second. You can learn more how we did that in the blog Calculating and searching 500 billion digits of Pi, by Francesc Campoy, Jen Tong, Ray Tsang, Sara Robinson.

In 2015, we calculated 250 billion digits of Pi, by Greg Wilson, Ray Tsang.

Source Code Edit

The source code for the REST API and demos are available on GitHub.