Menu

1 / 2

Adding an AI feature to a Flutter app without shipping your API key

DEV Community: fastapi·Ankur Kumar·1 day ago
#q9bX6Aw1
#devtofastapi#devto#dev#title#user
Long article (2811 words) — no AI summary yet.
Reading 0:00
15s threshold

A common first attempt at adding AI to a mobile app is to put the provider's API key in the app and call the API straight from Dart. It works on the first try, and it's a mistake. Anything inside an APK or IPA can be pulled out with free tools in a few minutes, and once someone has your key, they can run up your bill with requests that have nothing to do with your app.

The fix is the same as for any other secret: the app talks to your backend, and only the backend talks to the AI provider. This tutorial adds a small AI feature to the FastAPI + Flutter tasks app from an earlier tutorial : a "Break it down" button that turns a task such as "Submit November expenses" into a short list of steps with time estimates.

Along the way it covers the parts that matter once real users press the button:

getting structured JSON back instead of free text

treating user input as data, not instructions

turning AI failures into the same error format as the rest of the API

a per-user daily limit, so one account can't spend…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.