SwiftRelay

← All sprint notes

OpenAI Node.js SDK API Relay Setup in Three Lines

Agent quick startsEN

Three lines to connect the OpenAI Node.js SDK to SwiftRelay

Getting an API relay setup moving should not feel like a long configuration project. SwiftRelay is built around a simple promise: connect in minutes by copying three lines and running. There is no monthly fee and nothing to subscribe to. Top up a balance, and each call deducts only what it used. That makes SwiftRelay straightforward to try from a script, a service or a local development session.

For the OpenAI Node.js SDK, the first two lines set the endpoint and your key. Use the SwiftRelay OpenAI-compatible base URL:

01  export OPENAI_BASE_URL=https://api.fastapirelay.com/v1

Then place your SwiftRelay key in the API key variable:

01  export OPENAI_API_KEY=<your swft_ key>

The third line wires the OpenAI Node.js SDK to those environment variables:

const client = new OpenAI({ baseURL: process.env.OPENAI_BASE_URL, apiKey: process.env.OPENAI_API_KEY });

That is the whole starting point. The SDK client reads the SwiftRelay base URL and the swft_ key, so your existing OpenAI Node.js SDK code can use the relay without a monthly commitment. The API host for SwiftRelay is https://api.fastapirelay.com.

Before you run a billable request, top up your SwiftRelay balance. Available top-up amounts are $1.39, $6.94, $13.89, $27.78, $69.44 and $138.89. A small top-up is enough to test the connection and inspect the first call. New accounts also receive $0.22 in sign-up gift credit.

Choose a listed model with the exact token price in view

A useful cost habit begins before the request is sent: decide which model matches the job and check its current input, output and cache-read prices. SwiftRelay lists prices per 1M tokens on its pricing page, and your usage view lists tokens and cost per call. That visibility turns model selection into a practical decision rather than a guess.

  • DeepSeek V4 Flash is listed at $0.2639 per 1M input tokens, $1.06 per 1M output tokens and $0.006944 per 1M cache-read tokens.
  • DeepSeek V4 Pro is listed at $1.17 per 1M input tokens, $3.51 per 1M output tokens and $0.0389 per 1M cache-read tokens.
  • GPT-6 Astra is listed at $0.6597 per 1M input tokens, $3.28 per 1M output tokens and $0.0653 per 1M cache-read tokens.
  • GPT-6.1 Sol is listed at $0.1736 per 1M input tokens, $0.8542 per 1M output tokens and $0.0347 per 1M cache-read tokens.

These are the model identifiers for the OpenAI Node.js SDK: deepseek-v4-flash, deepseek-v4-pro, gpt-6-astra and gpt-6.1-sol. Keep the identifier and the price side by side when you write the request. If a task is simple, a lower input and output rate may suit it better. If the task needs a different listed model, switch deliberately and review the resulting per-call cost.

Example: a call using 1M input tokens, 1M output tokens and 1M cache-read tokens on GPT-6.1 Sol would deduct $0.1736 + $0.8542 + $0.0347 = $1.0625. The same token volumes on DeepSeek V4 Flash would deduct $0.2639 + $1.06 + $0.006944 = $1.330844. These sums are examples based on the listed per-1M-token prices, not quotations for a particular workload.

Trim input, output and cache reads with repeatable habits

The clearest savings usually come from changing how you build requests. Because SwiftRelay charges per token, every unnecessary token leaves the balance. Treat the prompt, the requested answer and any repeated context as three separate places to inspect.

First, keep instructions focused. Remove examples the model already understands, duplicated background and long passages that are not needed for the current call. Shorter input reduces the input-token portion of each request. Second, set a sensible output limit instead of accepting the largest possible response. If the task only needs a short classification or a brief structured result, a tight limit can prevent a long answer from inflating output-token usage.

Third, pay attention to cache-read behaviour. Cache reads have their own listed rate for each model, so repeated context can still be worth measuring. Use the usage list to compare calls that reuse material with calls that do not. The goal is not a vague promise of savings; it is a habit of checking the tokens and cost recorded for each call.

Example: on DeepSeek V4 Flash, 1M cache-read tokens cost $0.006944, while 1M input tokens cost $0.2639. That does not mean every application should cache everything, but it does show why the usage view is worth reviewing when context repeats across calls.

Finally, test with a small, representative request before sending a larger batch. SwiftRelay lists tokens and cost per call, so you can inspect the first result, adjust the prompt or output limit, and then continue. This short feedback loop is especially handy when you are moving a script from local testing into regular use.

Run a small top-up before scaling a busy workflow

Per-token billing lets you start at a size that matches your current test. The $1.39 top-up is a convenient first step for checking the OpenAI Node.js SDK connection. If the test behaves as expected, choose from $6.94, $13.89, $27.78, $69.44 or $138.89 according to how much usage you want ready in the balance.

There is no need to buy a fixed block of service in advance. Each call deducts only what it used, which is useful for scripts with uneven demand. It also gives you a straightforward way to compare the cost of different prompts and models: run the same task, then check the usage entries for tokens and cost per call.

SwiftRelay allows up to 20 live API keys per account. That gives you room to separate environments or services without creating an unlimited-key workflow. Keep the swft_ key out of source code, give each live key only the role it needs, and rotate or remove keys when they are no longer required. The usage list remains the place to confirm which calls consumed the balance.

Unused credit can be refunded within 11 days of a top-up, minus what was used and the payment fee. That window is another reason to begin with a measured top-up rather than loading a large balance long before you need it. Start small, confirm the setup, and let actual token use guide the next step.

Use referral rewards and dashboard support to keep the account tidy

SwiftRelay also includes a referral programme. You receive 14% of each top-up by someone you invited, and 3% from the people they invite. Rewards can be moved into your balance or withdrawn, with a $4.86 minimum for withdrawal. If you already enjoy a smooth API relay setup, sharing the three-line connection method can add credit to your own balance.

Account questions go through Messages in the dashboard, where login is required. There is no support email to hunt for. Keep your questions specific: include the model identifier, the endpoint you are using, the relevant usage entry and what you expected to happen. A clear record helps you and the support team work from the same facts.

A final cost-trimming habit is to review usage regularly. Look for calls with unusually large inputs, long outputs or repeated context. Adjust the prompt, cap the response where possible and compare the next call with the previous one. SwiftRelay keeps the figures visible, so you can turn each review into a concrete change.

Three lines, a topped-up balance and per-call visibility: that is the SwiftRelay way to run the OpenAI Node.js SDK. Sign up now, connect your swft_ key, and take the first clean lap.

Keep reading

Back for another lap?Log in