- Published on
Building A ChatGPT Apple iOS Shortcut
TL;DR?
Let's face it, most of us are time poor and fed up with scrolling through web pages full of annoying click-bait adverts to read an article.
What if there was a way to summarize a web page on iOS using ChatGPT to enhance our productivity that didn't require developing an app?
Enter Apple Shortcuts and the ChatGPT API from OpenAI
There is a little known, but very powerful feature in macOS and iOS called Shortcuts. Shortcuts are a great utility for automating tasks using multiple action steps, including calling a REST API, and can be created with minimal development experience. They can also be easily modified or shared with other people without needing to be distributed via the app store.
In March 2023, OpenAI enabled API connectivity for ChatGPT and Whisper APIs. As part of this, they also relied on system optimisations to deliver a 90% cost reduction for the use of ChatGPT so that API calls would be affordable at scale. In June 2023, OpenAI delivered a further 25% cost reduction on input tokens for the gpt-3.5-turbo
model.
This post shows how to build an Apple Shortcut to summarize a web page using the ChatGPT API.
Get your OpenAI API key
You can obtain an API key from OpenAI by logging into the developer portal and navigating to https://platform.openai.com/account/api-keys

Beyond trial use, API access requires setting up a payment method for billing which is invoiced on a monthly basis. OpenAI uses a default limit of $120 USD per month and although the gpt-3.5-turbo
large language model is inexpensive, I recommend setting a hard limit and soft limit which is sympathetic to your credit card. My use of the ChatGPT Shortcut for typical web browsing resulted in a daily cost of less than 5 cents for API calls so its easy to see how much value this Shortcut delivers for the money.
Create the shortcut
The high-level steps for the shortcut execution are as follows:
- Get the article body from the web page in Safari.
- Format the article body so that it can be sent in an HTTP POST request by removing the following characters:
- newline
- paragraph
- tab
- Remove double and single quotes from the article body so that it can be sent in an HTTP POST request.
- Submit an HTTP POST request with authorization in the HTTP headers and instructions to summarize text in a JSON request payload to the ChatGPT API.
- Parse the JSON response payload and display the results in a dialog.
Open the Shortcuts app and create a new shortcut called "Summarize with ChatGPT".
Add actions to the shortcut to build it out as shown below.

"Replace" actions are used to run a regular expression. Calling Replace ['"“”]
will remove double and single quotes. Calling Replace [\r\n\t]
will remove paragraphs, new lines, and tabs.

The value for the text field that starts with sk-...
should be updated to use your OpenAI API key.

The most complex part of this shortcut is the action which sends the HTTP POST request to ChatGPT with the "Get contents of" action. I have created the payload where the content of the web page is passed across in the Updated Text as follows:
{
"model": "gpt-3.5-turbo",
"messages": [
{ "role": "user", "content": "Summarize the following article text: [Updated Text]" }
],
"temperature": 0.2
}
For model
I opted to use the gpt-3.5-turbo
language model in my Shortcut with API calls priced at a reasonable $0.002 per bucket of 1000 tokens.
The messages
field contains the instruction for ChatGPT in the content sub-field.
I use a lower temperature
value of 0.2
which is a "hyperparameter" used in language models to fine-tune creativity. The default value for ChatGPT is 1.0. From the OpenAI documentation:
"The temperature value is a floating point number between 0 and 1. A value of 0 means the model will always choose the most likely token (i.e., it will always output the most common response), while a value of 1 means the model will treat all tokens equally (i.e., it will output a more diverse range of responses). Values between 0 and 1 interpolate between these two extremes."
Tweaking the value for temperature may alter the time it takes for ChatGPT to process an API call.
The HTTP request headers will set the content type to application/json
and the authorization bearer header value to your OpenAI API key.

When the HTTP response is received, the value for choices.1.message.content
is extracted from the JSON payload and shown in a dialog.
Configure the shortcut for use in the Share sheet
Open the Shortcuts app.

Edit the settings for the Summarize with ChatGPT shortcut by pressing "..." then select the option "Show in Share Sheet".

Press "Done" to dismiss the Details.
Add the shortcut to your favourites
Open Safari and press the up arrow at the bottom of the browser tab bar.

In the modal, scroll to "Edit Actions..." and find the "Summarize with ChatGPT" Shortcut. Press the green + button to add it to the action Favourites.

Press "Done" to dismiss the Actions.
Use the Summarize with ChatGPT shortcut
When you are browsing in Safari, press the arrow icon at the bottom of the tab bar.

From the Action sheet select "Summarize with ChatGPT". This will invoke your shortcut to call the OpenAI API and summarize the web page.

A summary of the web page content will be shown in a dialog which can be dismissed by pressing "Done".

Performance
I tested this on various sites and performance was relatively consistent with most invocations being completed between 7 and 10 seconds. It was interesting to observe that the text summary would sometimes differ for the same web page, even with a temperature
value of 0.2
which is used for generating output that is more deterministic and focused.
Validating your API key using a test request
If the shortcut doesn't work, check your account is in credit and API key is still valid. You can do this with Postman or curl
using a test payload and your API key.
curl --location 'https://api.openai.com/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer sk-...TbW' \
--data '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "What is a Large Language Model?"}],
"temperature": 0.2
}'
A successful request will return a response similar to the following:
{
"id": "chatcmpl-7XGRTWRNBR15HMOzdFdcXSDYhjMqT",
"object": "chat.completion",
"created": 1688162383,
"model": "gpt-3.5-turbo-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "A Large Language Model refers to a type of artificial intelligence (AI) model that is designed to generate human-like text based on the input it receives. These models are trained on vast amounts of text data from the internet or other sources and learn patterns, grammar, and context to generate coherent and contextually relevant responses.\n\nLarge Language Models utilize deep learning techniques, particularly transformers, to process and understand textual data. They are typically composed of multiple layers of neural networks that enable them to learn complex patterns and generate high-quality text output.\n\nThe size of a Large Language Model is determined by the number of parameters it has. Models like OpenAI's GPT-3, for example, have billions of parameters, allowing them to generate highly persuasive and contextually appropriate responses. These models can be fine-tuned for specific tasks like language translation, content generation, question-answering, and more, making them versatile tools for a wide range of applications.\n\nLarge Language Models have gained significant attention due to their ability to generate human-like text, but also raise concerns regarding ethical use, misinformation, and potential biases."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 14,
"completion_tokens": 220,
"total_tokens": 234
}
}
A typical error message will look like the following:
{
"error": {
"message": "You exceeded your current quota, please check your plan and billing details.",
"type": "insufficient_quota",
"param": null,
"code": null
}
}
Edge cases and error handling
Error handling in Apple Shortcuts is relatively basic. Parsing the content of a web page in reader mode to remove characters was tested against a variety of sites, although there may be some edge cases which weren't discovered during testing. You will see a dialog with the error if the shortcut fails to run succesfully.
Alternative implementations
Azure Cognitive Services also provide access to OpenAI APIs. You can create a model deployment in Azure and use one of the two generated API keys to call your own endpoint. This has the added benefit of being able to configure services using IaC such as Terraform or Azure Resource Manager (ARM) templates.
This shortcut could also be developed as a plugin delivering similar functionality for Chromium based browsers on desktop or Android mobile.
I recommend keeping a watchful eye on language models released by OpenAI as these will improve over time.
Get the shortcut
You can obtain the shortcut from here. Once installed, edit the shortcut to add your OpenAI API key.