How to Call a Language Model API with curl
A first API test should be small: one prompt, one request, and a response you can inspect. This walkthrough uses curl to call Vana API through its OpenAI-compatible interface. Vana API documents a chat completions endpoint that accepts a model identifier and a messages array. ([vanaapi.com](https://vanaapi.com/plug-in?locale=en))
§ Step 1: Prepare your terminal
Use Bash or Zsh for the commands in this walkthrough. Start by checking your curl installation:
1 curl --version
If the command is unavailable, install curl before continuing. The examples keep each command on one line so you can copy it without managing continuation characters. curl supports HTTPS requests, custom headers, and request bodies, which are the pieces needed for this test. ([curl.se](https://curl.se/docs/manpage.html))
§ Step 2: Configure your API key
Create a Vana API account, then obtain an API key for your requests. Set it in your terminal environment, replacing the placeholder with your actual key:
1 export VANA_API_KEY='YOUR_API_KEY'
Keep the placeholder in shared examples rather than substituting a working credential. Avoid including your key in screenshots, support messages, or committed scripts. For this walkthrough, use a temporary terminal session and remove the variable when you finish.
The request below passes the key in an Authorization header using the Bearer scheme, matching Vana API’s documented curl example. ([vanaapi.com](https://vanaapi.com/plug-in?locale=en))
§ Step 3: Build a minimal request
Use GPT-6.1 Sol for this example. Its documented API identifier is gpt-6.1-sol. Send the following command as one line:
curl --silent --show-error --fail-with-body 'https://api.vanaapi.com/v1/chat/completions' -H "Authorization: Bearer $VANA_API_KEY" -H 'Content-Type: application/json' --data-raw '{"model":"gpt-6.1-sol","messages":[{"role":"user","content":"Explain an API in two short sentences."}]}'
The endpoint, model identifier, and request structure follow Vana API’s OpenAI-compatible integration documentation. Notice that the full request address includes both /v1 and /chat/completions; the bare host is not the chat endpoint. ([vanaapi.com](https://vanaapi.com/plug-in?locale=en))
Keep the first prompt short and non-sensitive. Your immediate goal is to confirm that the credential, endpoint, and payload work together, not to evaluate the model’s performance on a complicated task.
§ Step 4: Understand the command
- --data-raw: Supplies the JSON request body and makes curl use POST unless another option changes the method.
- -H: Adds a request header. Here, one carries authentication and another declares JSON content.
- --silent --show-error: Hides the progress meter while preserving error messages.
- --fail-with-body: Returns a failure exit status for HTTP errors while retaining the response body for inspection.
These options let you inspect the response without the progress meter obscuring it. If your curl version does not recognize --fail-with-body, update curl or omit that option for the initial diagnostic request. ([curl.se](https://curl.se/docs/manpage.html))
§ Step 5: Inspect the response
Read the returned JSON before building automation around it. Vana API’s documented example accesses the assistant’s answer at choices[0].message.content. Start there, but keep the complete response while troubleshooting so you do not discard useful context. ([vanaapi.com](https://vanaapi.com/plug-in?locale=en))
Next, change only the prompt and repeat the request. Keeping the endpoint, headers, and model unchanged makes this a controlled second test. Once both requests succeed, save a placeholder-only version of the command as your reproducible starting point.
§ Step 6: Troubleshoot and clean up
If the request fails, check the error body before retrying. Compare your command against the example: confirm the environment variable, preserve the JSON quotation marks, and check the complete endpoint path. Vana API specifically documents HTTP 402 as an exhausted account balance. ([vanaapi.com](https://vanaapi.com/plug-in?locale=en))
For an additional diagnostic run, add --include to display response headers alongside the body. Redact credentials and sensitive content before sharing diagnostic output. ([curl.se](https://curl.se/docs/manpage.html))
When you finish, remove the temporary environment variable:
unset VANA_API_KEY
You now have a small request to return to whenever you need to separate connection or authentication problems from application logic.