--- type: Guide title: "Send one question to a language model through its API" description: "From a terminal in a MESA app, send one question to a CyVerse AI Verde model with curl, find the answer and the token counts in the reply, and see that a second call remembers nothing of the first." tags: [byte, p4, ai-agents, api, credentials] status: draft generated: { by: "claude-code/mythos-5.2", at: "2026-12-03T00:00:00Z" } stale_after: "2027-06-03T00:00:00Z" sources: - id: docs-agents resource: "https://idss-mesa.github.io/docs/apps/agents/" title: "AI agents in the MESA apps" author: "team:idss-mesa" - id: setup resource: "https://github.com/idss-mesa/jupyterlab/blob/main/latest/configs/aiverde-setup.sh" title: "aiverde-setup, the script that saves the AI Verde settings in a MESA app" author: "team:idss-mesa" - id: api resource: "https://platform.openai.com/docs/api-reference/chat" title: "Chat completions (OpenAI API reference)" author: "team:openai" --- # Send one question to a language model through its API !!! warning "Draft: not yet validated" The AI assistant that drafted this tutorial ran every command in MESA JupyterLab on 2026-12-03 (model `js2/muse-glimmer`) and saw the results described. It sent each request once; another model, or another try, may answer in other words. No person has yet followed the page. [Tell us what you find](https://github.com/idss-mesa/trainings/issues). An agent talks to its language model through an API: it sends text to a web address and gets text back. Sending one request yourself shows what goes in and what comes out. **You will:** have one reply from a model, and know where in it to find the answer, the model's name, and the token counts. **Time:** 10 minutes. **You need:** steps 1 and 3 of [Sign in and start an AI agent in a MESA app](start-an-ai-agent.md) done in this app session. If you set up your key in this terminal, load it first: `source ~/.config/aiverde/env`. ## Steps 1. In the terminal, make a scratch folder, then check that the settings are loaded: ```bash mkdir -p ~/work/api-test && cd ~/work/api-test echo "${OPENAI_API_KEY:+key loaded}" "$OPENAI_BASE_URL" "$AIVERDE_DEFAULT_MODEL" ``` You should see: `key loaded`, an address ending in `/v1`, and a model's name. The first part prints those two words and not the key. Never print the key itself. 2. Ask the service which models your key may use: ```bash curl -s "$OPENAI_BASE_URL/models" -H "Authorization: Bearer $OPENAI_API_KEY" | python3 -m json.tool | grep '"id"' ``` You should see: one line for each model; here, 14. 3. Write the request to a file. Paste all eight lines at once and press Enter: ```bash cat > ask.json < ask2.json curl -s "$OPENAI_BASE_URL/chat/completions" -H "Authorization: Bearer $OPENAI_API_KEY" -H "Content-Type: application/json" -d @ask2.json | python3 -m json.tool ``` You should see: a `content` that cannot name February. Here it quoted the new question back and said there was no earlier one. This call carried one message, and the model has nothing else. ## Check it worked You can point to the answer, the model, and the two token counts in the first reply, and the second reply shows no memory of the first. A chat or an agent seems to remember only because it sends the earlier messages again with each call. ## If it didn't **`Authentication Error, No api key passed in.`** The settings are not loaded in this terminal. Run `source ~/.config/aiverde/env` and start again from step 1. **Step 1 prints an empty line.** The same cause, or `aiverde-setup` has not been run in this app session. **An error that names the model.** Your key may not use the saved model. Put a name from step 2 in `ask.json` in its place. ## Next - Remove the scratch folder: `cd ~ && rm -r ~/work/api-test`. - [How a language model answers](../explainers/how-a-language-model-answers.md) - [Keep tokens and passwords out of saved files](keep-secrets-out-of-files.md) - Reference: [AI agents in the MESA apps](https://idss-mesa.github.io/docs/apps/agents/). *Not yet validated by a person. Drafted with [AI assistance](../about/ai-disclosure.md) on 2026-12-03; every command was run in MESA JupyterLab that day.*