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:

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:

  1. 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 /**).
  2. You did not add @imaginary to your TSDoc comment.
  3. 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.

Previous
Writing an imaginary function