Integrating your own AI model using OpenRouter.ai
| Summary | This article describes the implementation of different AI models for generating prompts in the Open ADC. |
| Applies to | AskiaDesign 5.5.3 and above |
| Written for | Scriptwriters and survey authors |
| Keywords | ADC; javascript; control; design; askiadesign; ai; prompt |
This goal of this article is to assist survey programmers with implementing their own LLM (Large Language Model) for the AI Prompting function availble in the Open ADC. For simplicity, we will be focusing on the aggregate site, OpenRouter.ai.
This article is meant as a supplement to the Prompting with Open ADC introduction and example QEX provided in that article.
The Basics
The prompt function of the Open ADC allows survey scripters to integrate prompt messages to respondents while they are filling in open-ended responses. However, in order to use the AI model function, you will need to fill in the following under the requisite routing that is required for the function to generate responses properly:
Header Tab
- URL: This will be set to https://openrouter.ai/api/v1/chat/completions for the purposes of this tutorial, as we are using this site's API calls.
- Authorization: This is the API Key that is generated via OpenRouter for your account, so your survey can communicate properly with the AI model. The only value that changes is TOKENVALUE; the "Bearer" prefix must remain, with a single space between it and your API Key.
Body Tab
- Model: This will be set to whichever AI model you are currently using. In this example, the GPT 4.1 Nano model is used.
Take note of the JSON format regarding "messages", "role", and "content". This will be explained further in the article.
Setting everything up
Navigate to OpenRouter.ai and set up an account. Once done, navigate to your account page and locate the API Key tab.
Once here, select "Create API Key". A few additional options will appear:
- Name: Self explanatory, you can name this key whatever you like.
- Credit limit: Total amount of credits to be used before the API stops accepting calls. Once this limit is passed your prompts will stop returning for respondents. Credits will be explained in another section.
- Reset limit: Resets your credit limit every X amount of time. Irrelevant if the credit limit is set to unlimited.
Once this is done, your key will generate. Make sure you write this down or save it in a password manager, as once generated you will not be able to see the full key again and must generate another if you lose track of it. Once you have this key, make sure you replace the Authorization value in your QEX file. For instance, if your key was generated as:sk-or-v1-00012345678910eeee
This would be the new value in your routing:
Now you need to decide on which AI model you will use. There are a plethora of options; however OpenRouter provides a robust search function when narrowing down LLMs. For this example, we will stick with GPT 4.1 Nano as our chosen model. We are specifically interested in the API tab, as that will give us the information needed to properly fill in the requisite information in our QEX file.
For purposes of inclusion in the Askia survey, we only want to focus on the typescript section.
You can see the example given from the model very closely resembles our survey's body section. Including the URL needed, and the "role","messages" and "content" types in the JSON body the API expects.
Since the Body in the QEX matches the expected JSON from the API, the only thing needed to be changed if desired is the "content", which gives the query to the AI model in question.
Credits & Costs
Although there are a few "free" models, for reactivity and accuracy, the better models come with a general per use cost.
Each model has it's own requisite cost, usually measured per request, or number of tokens. The specifics of each can be seen per model, as in this example:
Such costs are handled through credits on your OpenRouter account. The provider takes the total sum of requests, and OpenRouter deducts this from your credit cost. You can see exactly how much your model is costing per request in your Activity screen of your account.
Keep in mind that depending on what credit limit (if any) you placed on your API key, that your prompts will no longer return once this threshold is reached, unless you set a refresh on your limits in your API key options.