MyRelay

← Back to the notebook

Your First API Call with cURL, Explained

Start with one small question

Your first API call should answer a simple question: can you send a message and receive a useful reply? Leave document uploads, long conversations, and automation for later. Ask the model to explain an API in one sentence. A small test gives you fewer things to troubleshoot and a manageable result to inspect.

cURL is a command-line tool for transferring data. Here, it carries your request to an AI service and brings the response back to your terminal. You do not need to build an application first. This walkthrough explains the pieces you will encounter before you run the example. ([curl.se](https://curl.se/docs/manual.html))

Prepare your terminal and protect your key

Open your terminal and check whether cURL is available using your operating system’s guidance. If it needs installing, use the official installation instructions rather than an unfamiliar download.

Create a MyRelay account, then generate an API key in the dashboard. MyRelay’s connection help includes a cURL example for a first chat request, so use that as your starting point rather than assembling a request from unrelated tutorials. Its documented example uses GPT-6.1 Sol. ([myapirelay.com](https://myapirelay.com/how-to-connect?hl=en))

Treat your key like a password. Keep it out of screenshots, shared documents, and public repositories. For repeated use, prefer a protected environment variable over repeatedly pasting the secret into terminal history. Before sharing troubleshooting details, remove the key completely.

Understand the destination before sending anything

Open the cURL example in MyRelay’s connection help and identify its destination. The API base identifies the service; the chat endpoint identifies the operation you want that service to perform. Use the complete chat destination from the example, not the website address or the bare API base. ([myapirelay.com](https://myapirelay.com/how-to-connect?hl=en))

Keep that destination unchanged for your first attempt. Changing the address, model, and message together makes it harder to identify which change caused a problem. Your first useful modification should be the short question you want answered.

Read the headers and message body separately

The request has headers and a body. In MyRelay’s OpenAI-compatible example, the authorization header carries your key using bearer authentication. The content-type header identifies the body as JSON, a structured text format. Replace the example credential with your own key without changing the surrounding authentication structure. ([myapirelay.com](https://myapirelay.com/how-to-connect?hl=en))

The body selects a model and supplies a list of messages. A user message contains the question you are asking. Keep the documented model identifier intact: an API identifier is not necessarily written like the model’s display name. ([platform.openai.com](https://platform.openai.com/docs/api-reference/chat/create))

When editing the question, preserve the surrounding quotation marks, commas, and brackets. cURL can transmit JSON without validating its structure, so a small punctuation mistake can produce a rejected request. Avoid adding optional settings until the basic example works. ([everything.curl.dev](https://everything.curl.dev/http/post/json.html))

Send once and inspect the response

After reviewing the destination, credential, and question, run the prepared example once. Wait for the response before trying again. Read the returned text rather than treating the terminal finishing as proof of success.

A successful network transfer is not necessarily a successful API request. By default, cURL can complete a transfer even when the server returns an HTTP error. Inspect the response body and, when troubleshooting, the HTTP status. Status codes in the 200 range indicate HTTP success; errors need investigation rather than immediate repetition. ([everything.curl.dev](https://everything.curl.dev/http/response.html))

Check the cost before expanding the experiment

Review the request’s tokens and cost in MyRelay. Its billing guidance says charges reflect actual token usage, including applicable cache activity. Use the recorded charge as evidence, not the length of the visible answer alone. ([myapirelay.com](https://myapirelay.com/how-to-connect?hl=en))

Set a small personal testing allowance and change one thing per attempt. Once the first call works, try a slightly different question while keeping everything else fixed. You now have a repeatable baseline: a known destination, a working credential, a valid message, and a cost you have checked.

More to read