A swift client for OpenRouter

December 31, 2024 by Lou Zell

OpenRouter aims to simplify the developer experience of integrating with multiple LLM providers. They built a unified API to add chat completions, structured outputs, or vision to your products. With a single string change, OpenRouter will switch the provider that fulfills the request. It's very nice! The API feels familiar, as it's derived largely from OpenAI's.

Before today, adding OpenRouter to your Apple app meant cooking up a swift client yourself. That is no longer necessary. An MIT-licensed swift client for OpenRouter is baked into AIProxySwift release 0.50.0. You can use this client to make calls directly to OpenRouter, or proxy them through our abuse protection backend.

Sending requests straight to OpenRouter is great for prototyping and for BYOK use cases (where your app's customers provide their own API keys). For all other production use cases, we recommend using AIProxy as your backend. Our backend's security features and monitoring ensure that you get a predictable bill from OpenRouter each month.

There are two OpenRouter features that are great for app developers:

  • Swap a single string to change the model that serves the request.
  • List fallback preferences for routing requests to secondary providers when the primary is offline.

See the snippets in our docs for crafting requests that use these features. Happy building!