Hello everyone,
I am a Digital Art student with limited programming experience, and I am currently working on a project that involves developing a backend module for an AI-based AR game system using 8th Wall. The goal is for users to take photos using 8th Wall, upload them to OpenAIās server, and have OpenAI recognize objects and their positions in the photos.
Here are some specific questions Iām encountering:
Module Setup: I am unsure how to properly set up the backend module to handle photo uploads and communicate with OpenAIās API. Any guidance on the architecture or sample code would be greatly appreciated.
Bug Reports: I try to creating a backend gunctions, but it meets problme
Integration with OpenAI: If anyone has experience integrating 8th Wall with OpenAI, I would love to hear about your approach and any challenges you faced.
Thank you in advance for your help and advice. I am eager to learn and improve my skills in this area.
Hi, welcome to the forums!
Have you taken a look at the Word Guesser sample project that uses Backend Functions in a module?
Hi Chow! 
NPM modules like Express arenāt available at the moment, but the good news is that you donāt need them to connect to external APIs like OpenAI.
You can simply use fetch() requests inside a backend function (e.g., index.ts) to handle everything. Hereās a simplified overview:
- Backend Setup:
Inside your backend handler file, declare your environment OpenAI API variables.
Use conditional logic like if (event.httpMethod === āPOSTā) to handle incoming requests.
Then, for specific routes (e.g., if (event.path === ā/uploadPhotoā)), use fetch() to send the uploaded image to OpenAIās API and process the response.
- Connecting Backend to Frontend:
First, import your backend module in module.js.
Then, in your 8th Wall frontend code, also import that module so you can use it.
Use fetch() in the frontend to call your backend route (e.g., /uploadPhoto) and send the photo data.
This way, youāre passing data from the front end ā backend ā OpenAI ā and back.
No need for Express or npm installs ā just clean serverless-style logic using plain JavaScript.
Hope this helps!
2 Likes
Thanks for the sharing, I will try it later.
Thanks for your sharing, really appreciate your kind help !
Could you please tell me more information about calling OpenAIās API in the backend service, or is there have any program template to achieve the similar effect? I am really appreciate for your help !
I also meet a new problem in create environment variables: When I try to input the OpenAIās API key, it showes āKey cannot exceed 128 charactersā.
I had no idea the OpenAI API keys were that long. Let me look into seeing how we can improve this. In the meantime you could use two Environment Variables and combine it into one string in your code. 
Hi, after taking a look at it again it looks like youāre trying to put your API key where youāre supposed to put the NAME of the value.
So in this case the key would be something like OPEN_AI_SECRET
, which you would put your key in the module config when you turn off development mode.
Then in your code youād use it like process.env.OPEN_AI_SECRET
.
Really thanks for your kind help, I will try it later 
Offical Module for OpenAI
I also founded an official 8th Wall Module for OpenAI, it supports generate image or story from text the prompt, but does it support uploading a photo to OpenAIās server to analysis it? Thanks for your kind help!
Iām still learning OpenAIās API for another project Iām working on, so Iām not yet sure how to fully implement that specific functionality. But from what Iāve seen, it works like most other APIsājust use fetch() with the endpoint URL and the required options from the docs, and you should be good to go.
If you copy and paste my previous message into ChatGPT, it might help you generate the backend code you need.
After I release my game, if thereās enough interest, Iād be happy to make my database module public to help make this process easier for everyone! 
Thanks for your reply! Since I am still new to fetch() and backend development, I hope to see you publish your own database module. Good luck!
1 Like
Update 1:
I have successfully implemented the frontend functionality, which allows users to upload pictures from their computer or phone. However, I am still facing issues with the backend function. I believe the main problem lies with the environment variable and the OpenAI API key.
Here is my error log.
Youāll likely need to make OpenAI calls directly using fetch
rather than relying on the OpenAI module as we work to port it over to Studio.
ok, thanks for your help.
So you mean I donāt need to make OpenAI API calls through the backend module I developed, but just use Fetch in the frontend program?
If you make the fetch calls directly from the frontend youāll be exposing your API key to the client. The reason for using a backend function is to proxy your fetch calls to OpenAI through 8th Wall so the client never sees the API key.
I attempted to store my API key in an environment variable, but the system returned an error stating, āLabel cannot exceed 128 characters.ā I then tried splitting the key across two environment variables and combining them into a single string in my code, but this also resulted in an error.
The label isnāt where you put the key. The label is how you reference the variable in code.
You put the actual key in your module config once you turn off development mode.