Advanced Guides
Troubleshooting
Learn what to do when things go sideways.
Things not going the way you thought they should? See if your problem is covered here.
When I call an imaginary function, I get an error that I need an OPENAI_API_KEY environment variable.
In order to use imaginary-dev
, you need to open an account with OpenAI and acquire an OpenAI API key. If you don't provide that key to your application you will get an error message that says:
TKTK error message not written yet
To avoid this problem, first open an account with OpenAI if you don't already have one. Then, go to your API key page and copy one of your API keys. Finally, put this API key into an environment variable named OPENAI_API_KEY
. Different ways of running your application have different ways of supplying environment variables:
- If you run your application at the command line, you can prepend the normal command you use with
OPENAI_API_KEY=<your API key>
. - If you are using a
.env
file with the excellentdotenv
npm package, you can just add another line to your.env
config file. However, make sure that you do not check your.env
file into source control! - If you are developing with a Next.js, read their documentation on environment variables.
- If you are developing with Vue, read their documentation on environment variables.
- If you are deploying to Netlify, read their documentation on environment variables.
- If you are deploying to Vercel, read their documentation on environment variables.
I received an error that my imaginary function was not defined.
If you receive an error like:
ReferenceError: myImaginaryFunction is not defined
it's likely that the imaginary-dev
compiler did not compile your function. There are three common reasons for this:
- You didn't include a comment before your function, or your comment wasn't in TSDoc format (i.e. the comment did not start with a slash and two asterisks
/**
). - You did not add
@imaginary
to your TSDoc comment. - Your project is not set up to run the
imaginary-dev
compiler.
My imaginary function runs, but it doesn't give me the results I want.
If your imaginary function returns, but it doesn't give you the results that you were expecting, the first thing to do is to start changing the function comment and name and test new versions of the function. Use more evocative language, be very specific about what you want the function to return and what you think it should do. Also try being directive about what the function should not do, especially if you find the imaginary function falling into the same patterns over and over again.
I need to use imaginary-dev
in a web app, but it doesn't work in the browser.
OpenAI's API is not intended to be used directly from browsers, and if you do so you will be revealing your OpenAI API key to the world and potentially allowing other people to rack up charges on your OpenAI account. For this reason, you should always use the OpenAI API on the server-side and make an API call from your browser frontend to the server. This keeps your API key safe and hidden from potential bad actors.
In Next.js, you can put your imaginary functions into files under /src/pages/api
, and they will automatically be API calls for your frontend to call. Other web frameworks have similar features.