Make your first API request before connecting an agent.
You have configured a model or gateway. What do you actually run next? Viewers asked this under my 9Router setup video, alongside questions about authentication and paid plans. This follow-up starts with a local example you can run and inspect.
The example uses a local mock server, not a language model. It needs Node.js 22 or later, costs nothing in provider usage, and does not read your API keys. Passing it verifies the example’s request handling, not a connection to 9Router or a paid provider.
1. Know which credential you need
- Chat subscription: access to a provider’s chat product under its current plan.
- Provider API key: a credential for the provider’s developer API, with its own billing and limits.
- Gateway key: access to your router. The router still needs a supported upstream provider connection.
For example, Anthropic documents Claude subscriptions and Console API access as separate products. Check the current Claude billing explanation before assuming a chat plan covers API requests. A free local router does not establish that the model calls behind it are free.
2. Run the local example
Clone this site’s public repository and run the example. It uses only Node’s built-in modules; no npm install is required for this command.
git clone https://github.com/mikeholp87/ai-income-lab.git
cd ai-income-lab
node public/examples/first-api-request.mjs
You can also download and inspect the example. Its server binds only to 127.0.0.1 on an available port, checks three requests, and closes afterward.
3. Read the result
Wrong key: HTTP 401
Wrong model: HTTP 404
Valid request: HTTP 200
PASS: local request checks. No provider API was called.
These are the expected results from the included executable checks. The first two requests deliberately fail. The third returns a fixed message, connection-ok (local mock). Nothing here measures model quality, fallback reliability, or token savings.
4. Understand the request
The client sends JSON to POST /v1/chat/completions. It supplies a bearer key, a model ID, and a message. The server reads those values and chooses a response:
{
"model": "demo-model",
"messages": [{ "role": "user", "content": "Reply with connection-ok" }],
"stream": false
}
demo-only and demo-model belong only to this mock. They will not authenticate a real service. The example also stops after five seconds and rejects redirects, so it does not silently forward its authorization header elsewhere.
5. Move to your actual gateway
Once the local example makes sense, use your gateway’s own request example. The 9Router project documents a chat-completions endpoint and model discovery. Copy the base URL and exact model or combo ID from the version you installed; do not reuse the mock values.
- Confirm the gateway address belongs to your installation. Keep local practice on loopback; use HTTPS for a remote service.
- Configure a supported provider connection and check that provider’s billing before sending a real request.
- Keep the real key in a server-side environment variable. Never place it in browser JavaScript, a public repository, or a screenshot.
- Send one short, non-sensitive test prompt using the gateway’s documented request format and token limit.
- Check both the response and the provider usage report. A successful response does not prove zero cost.
- Only then configure the same endpoint and model in your editor or agent.
When it fails
- Connection refused: check that the gateway is running and that the host and port match its UI.
- 401 or 403: check which service issued the credential and whether that connection is authorized. A gateway key and a provider key have different jobs.
- 404: check the endpoint path and exact model ID. This mock uses 404 for an unknown model; real services may report a different status.
- 429: inspect the provider’s quota and rate-limit details. Do not assume retries are free.
- HTTP 200 with the wrong format: verify that the service supports the API format your client expects. This example expects a non-streaming response.
Source and next step
Read the complete example. For a production example with a saved fallback, continue with the React YouTube-feed guide.