Use Expo API Routes to securely interact with the OpenAI API.
app/api/generate+api.ts: Expo API Route that interacts with the OpenAI API.app/index.tsx: Screen that uses the API Route to prompt the user and display results..env: The environment variable file with references to your secret OpenAI API key.
npx create-expo-app -e with-openaiReplace OPENAI_API_KEY=YOUR_KEY in .env with your OpenAI API key.
Replace origin in the app.json with the URL to your production API Routes domain. This enables relative fetch requests.
{
"expo": {
"plugins": [
[
"expo-router",
{
"origin": "https://my-expo-website.com"
}
]
]
}
}Ensure you upload your environment variables to wherever you host the web app and API Routes.
Deploy on all platforms with Expo Application Services (EAS).
- Deploy the website:
npx eas-cli deploy— Learn more - Deploy on iOS and Android using:
npx eas-cli build— Learn more