Skip to content
/ genai-api Public template

Supercharge Apple’s Shortcuts using Cloudflare Workers and Gemini within minutes (and for free, up to hundreds of requests per day) ☁️✨

License

Notifications You must be signed in to change notification settings

louisbrulenaudet/genai-api

Repository files navigation

Bodyboard Thumbnail

Supercharge Apple's Shortcuts using Cloudflare Worker and Gemini within minutes ☁️✨

Biome License Known Vulnerabilities Zod

This TypeScript API built with Hono, OpenAI, and deployed as a Cloudflare Worker aims to boost the performance of Apple's Shortcuts by providing a seamless integration with generative AI capabilities, allowing users to create more powerful and intelligent shortcuts and leveraging the full potential of information extraction provided by the Apple ecosystem.

The objective of this repo is to provide a very simple and easy-to-use API for developers to integrate generative AI capabilities into their shortcuts in a minute. You just have to download this repository, slightly edit the configuration files, notably the wrangler.jsonc file, and run make init (eventually make update), then:

wrangler secret put GOOGLE_AI_STUDIO_API_KEY

Wrangler will prompt you to enter your API key, which will be securely stored as a secret environment variable in your Cloudflare Worker. If you don't have an API key yet, you can get one from the Google AI Studio.

Then, you need to put a bearer token for security reasons:

wrangler secret put BEARER_TOKEN

Once you have set up the secrets, you can deploy the API to Cloudflare Workers using:

make deploy

Here you go! Your API is now deployed and ready to use. You can test it by sending requests to the Cloudflare Workers URL provided in the output. The completion endpoint must be accessible pinging something like https://your-cloudflare-worker-url.com/api/v1/completion.

API Usage

Providers & Models

  • Providers: google-ai-studio
  • Models: gemini-2.5-flash, gemini-2.5-flash-lite, gemini-2.0-flash, gemini-2.0-flash-lite

POST /completion

The API supports both text and image input (multimodal). You can send images (as data URLs) alongside text in your requests, enabling advanced use cases such as visual question answering, image captioning, and more.

Send a POST request to /completion with a JSON body:

POST /completion
Content-Type: application/json
Authorization: Bearer your_token
X-API-Key: your_provider_specific_api_key

{
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "What is in this image?"
        },
        {
          "type": "image_url",
          "image_url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
        }
      ]
    }
  ],
  "temperature": 0.7,
  "model": "gemini-2.0-flash"
}

Or, with only text:

POST /completion
Content-Type: application/json
Authorization: Bearer your_token
X-API-Key: your_provider_specific_api_key

{
  "messages": [
    {
      "role": "user",
      "content": "What is the capital of France?"
    }
  ]
}

Request Parameters

  • messages (array, required): List of message objects, each with:
    • role (string, required): One of "system", "user", "assistant", "developer".
    • content (string or array, required): Either a string (text) or an array of content blocks:
      • Text block: { "type": "text", "text": "..." }
      • Image block: { "type": "image_url", "image_url": "<data URL>" }
        • Image must be a valid data URL.
  • temperature (number, optional): Sampling temperature (default 0.2, range 0–2).
  • provider (string, optional): Provider name (default: google-ai-studio).
  • model (string, optional): Model name (default: gemini-2.5-flash).
  • reasoning_effort (string, optional): Reasoning effort level.

The response will be plain text with the model's completion.

Apple provide a helpful guide here that you can follow to create your first shortcut using API calls.

Authentication:

  • Always include the Authorization header with your Bearer token.
  • You may also send an X-API-Key header to use a provider-specific key for requests, without needing to rotate secrets in environment variables.

Without the Authorization header, the request will fail.

Development

If you want to contribute to the development of this API or simply run it locally, you can follow these steps:

  1. Clone the repository:
git clone https://github.com/louisbrulenaudet/genai-api.git
cd genai-api
  1. Install dependencies:
make init
  1. Set up environment variables in .dev.vars:
CLOUDFLARE_AI_GATEWAY_BASE_URL=https://gateway.ai.cloudflare.com/v1
CLOUDFLARE_ACCOUNT_ID=your_account_id
CLOUDFLARE_AI_GATEWAY_ID=your_cloudflare_ai_gateway_id
GOOGLE_AI_STUDIO_API_KEY=your_api_key
BEARER_TOKEN=your_bearer_token
  1. Start the development server:
make dev

The API runs locally on port 8788.

Makefile Commands

Command Description
init Initialize the project
update Update dependencies
dev Run development server
deploy Deploy the application
format Format codebase with Biome
lint Lint codebase with Biome
types Generate TypeScript worker types
cloc Count lines of code in src/

Feedback

If you have any feedback, please reach out at [email protected].

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •