BazaarLinkBazaarLink
Sign in
← All articles
Published 2026-09-18 · · Author:BazaarLink · AI API · API AI · API integration · Beginner guide · Node.js

What Is an AI API? Beginner Setup, Pricing and Errors

AI API vs. ChatGPT: learn API keys, Base URL, model IDs, a Node.js example, token costs, 401/403/429 errors, and how to choose a Taiwan-ready platform.

Want your website to answer customer questions, condense a document into a summary, or have an n8n workflow generate replies automatically? What you need is an AI API that lets your program call a model. A membership on a chat website usually is not enough for your own program to use it.

An AI API is an interface that lets your program send data to an AI model over the internet and get results back. You are responsible for the application, the data and the user flow; the model service generates the response. When you search for "API AI," you are usually looking for tutorials or providers for this kind of interface.

This article starts from making your first text generation API call: first distinguish accounts from keys, then run a small example, and finally understand the costs and errors. Images, video and speech also have AI APIs, but their request formats and billing units differ, so text model estimates should not be applied to them directly.

Verification date: September 19, 2026. The catalog check below was actually run; the text generation example was not run as a paid call, so generation quality, latency and charges have not been measured.

How is an AI API different from the ChatGPT web app?

On a chat website, you paste your question yourself and read the answer. With the API, a program sends the question and passes the answer back to your website, customer service system or workflow. The API does not automatically build a complete product for you: login, data permissions, the user interface and error handling are still your application's responsibility.

For example, to build a customer service summary feature, the flow could be: the customer service system pulls a conversation → your backend calls the model → the summary is saved back to the ticket. The model does not automatically know your company's return and exchange rules just because it received an API request; you need to provide the relevant data and limit what actions it can take.

Also do not mix up a chat subscription with API credits. OpenAI explains that ChatGPT and the API platform have separate billing systems, and API usage is charged separately; buying ChatGPT Plus does not fund your own program. OpenAI billing help

If you only organize data occasionally by yourself, a ready-made chat tool may be enough. Starting to integrate an API is worthwhile when you need automation, want to connect to your own product, or need multiple users to operate within the same business process. For the difference between the two purchasing approaches, see Taiwan companies buying AI: API or subscription?

Before you integrate, get these three things right

The most confusing parts of the first setup are the API key, the Base URL and the model ID. They should all come from the same service configuration:

  • API key: proves which party sent the request and assigns usage to the corresponding account. It is not the login password for a chat website.
  • Base URL: the starting point for requests from your program. Using BazaarLink's OpenAI-compatible interface as an example, it is https://api.bazaarlink.ai/v1.
  • Model ID: specifies which model to use for this call. Copy it from the service's model catalog; do not guess from a product display name.

"OpenAI-compatible" means the interface accepts similar request and response structures; it does not mean all models, parameters and tools are exactly the same. OpenAI's Chat Completions documentation also notes that parameter support varies by model. This article uses that interface to demonstrate a basic text request; it does not mean that new OpenAI projects should prefer it. official Chat Completions documentation

If you use BazaarLink, you can first log in, then create a test key on the API key management page. The full steps are in the API key guide, and the current interface and parameters are based on the API documentation.

Keep keys in backend environment variables, not in frontend JavaScript, GitHub, screenshots or tutorial comments. For your first test, use dummy data, such as "Help me shorten this sentence," and do not run it directly on customer lists, medical records or full internal documents.

Check the model catalog first, then send the first text request

Do not start by connecting a full customer service bot. Do two things first: confirm you can read the model catalog, then confirm your program can parse a single text response. That way, when something fails, you can tell whether the problem is the URL, permissions, the model name or the application logic that follows.

Step 1: Read the catalog only, with no model charges

On September 19, 2026, we actually read BazaarLink's public GET /v1/models: the HTTP status was 200, and the response contained 175 model entries. The aliases of qwen3.7-flash include qwen/qwen3.7-flash, and the example below uses that full name. The catalog changes over time, so 175 is not a fixed promise; query it again before production use. public model catalog

The code below uses fetch, which is built into Node.js 18 and later, so no separate SDK is needed. Save the program as ai-api-demo.cjs:

const baseUrl = "https://api.bazaarlink.ai/v1";
const model = "qwen/qwen3.7-flash";

async function readJson(response) {
  const text = await response.text();
  let body;
  try {
    body = JSON.parse(text);
  } catch {
    throw new Error(`HTTP ${response.status}: response is not JSON`);
  }
  if (!response.ok) {
    throw new Error(
      `HTTP ${response.status}: ${JSON.stringify(body.error ?? body)}`
    );
  }
  return body;
}

async function main() {
  const catalog = await readJson(await fetch(`${baseUrl}/models`, {
    signal: AbortSignal.timeout(30_000)
  }));
  const selected = catalog.data.find((item) =>
    item.id === model || item.aliases?.includes(model)
  );
  if (!selected) throw new Error("The catalog does not contain the example model; choose a valid model ID");
  console.log("Found model:", selected.id);

  // By default, only read the catalog; add --generate to send one generation request that may incur charges.
  if (!process.argv.includes("--generate")) return;
  const apiKey = process.env.BAZAARLINK_API_KEY;
  if (!apiKey) throw new Error("Set BAZAARLINK_API_KEY first");

  const result = await readJson(await fetch(`${baseUrl}/chat/completions`, {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${apiKey}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      model,
      messages: [{ role: "user", content: "Introduce an API in one sentence." }],
      stream: false,
      max_tokens: 2048
    }),
    signal: AbortSignal.timeout(90_000)
  }));
  console.log("Reply:", result.choices?.[0]?.message?.content);
  console.log("Finish reason:", result.choices?.[0]?.finish_reason);
  console.log("Usage:", result.usage);
}

main().catch((error) => {
  console.error(error.message);
  process.exitCode = 1;
});

Run node ai-api-demo.cjs in the terminal. This step only reads the public catalog and does not send any text generation request. The program should print the model ID it found; if it cannot find it, update the model name first instead of repeatedly retrying an invalid name.

Step 2: Set the key and run one explicit generation

In Windows PowerShell, you can use $env:BAZAARLINK_API_KEY = "your test key"; on macOS or Linux, use export BAZAARLINK_API_KEY="your test key". This setting only applies to the current terminal session and may not persist after you close it; do not publish screenshots that show commands containing a real key.

After confirming your account balance and permission for this model, run node ai-api-demo.cjs --generate. This step sends one generation request and may incur a charge. The response text is not a fixed answer; when it succeeds, check the usage and the finish reason together.

The max_tokens: 2048 in the example is an output limit. It does not mean every call uses 2,048 tokens, and it is not a dollar cap on cost. Reasoning models may use part of the output budget for thinking; if the finish reason is length, first check whether you hit the limit, and do not treat a blank or incomplete answer as an integration failure right away. Support for this parameter varies by model; follow that service's documentation.

This article has verified that the catalog is readable and the example model name is valid. It did not run the paid generation step above, and it does not claim any response speed or actual charge. Before using this in a production product, still run one small test on your own account.

How are AI API costs calculated? Separate tokens from request counts

Text generation is usually priced separately for input and output. Input includes the messages you send and any context; output is the content the model generates, and some models also count reasoning usage. A token is the unit a model uses to process text; it is not the same as a Chinese character count or an English word count. OpenAI API pricing documentation

The basic estimate for general text usage is:

Input tokens ÷ 1,000,000 × input price per million tokens
+ Output tokens ÷ 1,000,000 × output price per million tokens
= Base cost of this text usage

Take today's public catalog base tier for Qwen3.7 Flash as an example: input is US$0.03 per million tokens, and output is US$0.13 per million tokens. The raw catalog values pricing.prompt and pricing.completion are dollar prices per token, so do not misread them as per-million prices. Pricing source: public model catalog

Suppose one call uses 1,000 input tokens and 500 output tokens, with no caching or other charges:

1,000 ÷ 1,000,000 × 0.03 = US$0.000030
  500 ÷ 1,000,000 × 0.13 = US$0.000065
Total                    US$0.000095
10,000 identical requests US$0.95

This is a hypothetical scenario calculated at list prices, not an actual charge record for the example above. That model catalog also lists price tiers for inputs above 32,768 and 262,144 tokens, so the base unit prices above should not be applied to long documents. Images, video, search tools, caching and batch jobs may follow different rules.

When budgeting monthly, the most commonly missed item is resent conversation history: by the tenth round, what you send may include the earlier messages plus the new question, not just the tenth question. Attaching the full document every time, or retrying indefinitely after errors, also pushes usage up. Set a budget on your test key first, record the usage from each call, and then decide whether you need to switch models, shorten the context or use caching.

Your account's dollar usage charges also do not equal the total New Taiwan dollar payment. The BazaarLink billing documentation explains that top-ups incur a 10% transaction fee, and eligible New Taiwan dollar channels are subject to an additional 5% business tax; check exchange rates, payment channel fees and invoice eligibility before paying. To compare different models and larger workloads, see AI API price comparison and cost estimates.

How do you choose an AI API platform? Check your constraints first, then compare unit prices

OpenAI, Anthropic Claude, Google Gemini and other model providers each offer their own APIs; gateways can put multiple models behind a more consistent entry point. For beginners, the most important question is not getting the most models at once, but whether the entry point meets your use case and management needs.

Our recommendation: if you use only one model provider, need that provider's latest proprietary features, and can handle payment and key management yourself, consider going directly to the original provider first. That option has one fewer forwarding step. But when you need to switch between multiple models, track team usage by owner, or arrange Taiwan payments and invoices, a hosted gateway is worth comparing. If company policy does not allow data to pass through a third party, address the data policy first; changing only the Base URL does not solve that.

Before choosing a platform, clarify at least these five things:

  1. Features: Does your model actually support image input, tool calling and structured output? A model with the same name does not mean every parameter works.
  2. Billing: Does the platform show usage unit prices or the total payment cost? At which step are exchange rates, platform fees, taxes and payment processing fees charged?
  3. Limits: How many requests per minute can you send, how many can run concurrently, and how long can a long request run before timing out? Do free credits have eligibility requirements or expiry conditions?
  4. Data handling: Where do requests get forwarded, what content is retained, how long until it is deleted, and who can access it? Do not decide based only on the word "secure."
  5. Management: Can you create separate keys per project, set spending caps, revoke keys, and see actual usage?

BazaarLink provides an OpenAI-compatible entry point, so you can use multiple models in the catalog through one entry point, and offers New Taiwan dollar pricing and an eligible electronic unified invoice channel. However, "a Taiwan company provides the service" does not mean all models process data only in Taiwan; enterprises with data region or compliance requirements should first confirm the available routes and contract terms. current service and billing documentation

To compare the responsibility boundaries of gateways, routers and relay services, read What is an AI API gateway. If you need a company tax ID, a specific invoice format or a monthly billing arrangement, confirm before paying; do not top up first and then guess whether it can be expensed.

If the connection fails, check in this order

First confirm the Base URL, then the model ID, and finally the status code and the error code in the response. The same HTTP status can have different causes, so do not assume the platform or model is at fault based on the number alone. The table below shows directions to check, not a complete error table shared by every service; for BazaarLink's actual error codes, refer to the API documentation.

HTTP statusCheck firstDo not do this
400Required fields, model name, parameter support, context lengthDo not resend the same request unchanged over and over
401Whether the key is set, whether it has expired, whether it belongs to this platformDo not substitute your chat login password or another platform's key
403Account or model permissions, free-tier eligibility, content and safety restrictionsDo not assume it is always insufficient balance
404Whether the URL and route exist, and whether the model is still offeredDo not append /v1 twice
429Request rate, concurrency and usage limits, and the error codeDo not increase concurrency and force resends
5xx or timeoutPlatform status, response content, time of occurrence, and request ID (if any)Do not ignore usage that may already have occurred, or keep resending indefinitely

Check successful responses as well. If your program only prints undefined, first look at the raw response structure and the finish reason: in streaming mode, the response cannot be read as a single JSON object, and a tool call may not produce a regular text answer. When debugging, keep only the status code, timestamp, model ID and necessary error details; do not paste keys or complete customer data into public forums.

The standard for completing a first integration is simple: you can send a small request with a test key, correctly receive the response, see the usage, and know where to look when something fails. Once you can do those four things, integrate the API into the real business process; deciding which models you need and what your monthly budget is will be easier than looking at a ranking list.

FAQ

Can I use an AI API without coding?

You can use it through existing tools or low-code workflows that support API connections, but the tool must let you set the endpoint, key and model of the service you choose; not every chat tool accepts a custom API. If you only want to ask questions yourself, a ready-made chat service is usually simpler.

I set the environment variable, why does the program still say the key is missing?

Confirm the variable names match exactly, and start the program in the same terminal where you set the variable. A service that is already running may not pick up environment settings you change later; when deployed in a container or the cloud, set them in that runtime environment, not only on your own computer.

Can an AI API automatically read our internal network or ticketing system?

Having an API does not mean the model can access your internal systems. The application must first obtain legitimate access, retrieve the necessary data, and provide it to the model in a supported request format; only provide data that the user is authorized to view.

Why are the answers different when I ask the same question twice?

Generative models can produce different answers, and model versions, parameters and the context sent may also differ. When validating an application, check whether answers match your rules, facts and format rather than whether every word is identical. Do not treat one seemingly correct answer as a quality guarantee.

The API can go online, so does the model know the latest information?

Sending an API request over the network does not mean the model automatically searches the web. When you need current information, the application should supply verified data, or use a search tool that the service explicitly supports, and check the cited sources and any extra fees.

After an AI API returns an answer successfully, can I send an email or modify an order directly?

Getting a text response does not mean the model has been authorized to take action. Sending emails, issuing refunds or modifying orders should be validated by your system against data and permissions, with manual confirmation when needed; never perform operations with financial or legal effects just because the response is HTTP 200.

Try BazaarLink now

TWD billing · Taiwan invoices · leading AI models · OpenAI-compatible API

Sign up / Log in for freeEnterprise inquiries
Related posts
video generation API · Wan 3.0 · Veo 3.1 · MiniMax H3 · Grok Imagine Video · Seedance 2.5 · Kling
New video generation models on BazaarLink: Wan 3.0, Veo 3.1, MiniMax H3, Grok Imagine Video, Seedance 2.x, Kling
Kimi K3.1 Pro · Moonshot AI · Kimi API · Artificial Analysis · TWD conversion · AI API pricing · Taiwan unified invoice
Kimi K3.1 Pro API Pricing in TWD: AA Index 55.1, $2 / $10, 1M Context
Claude Haiku 5.5 · DeepSeek V4.1 Flash · GLM-5.3-Flash · MiMo-V2.6-Flash · Model Comparison · Pricing
Haiku 5.5 vs DeepSeek, GLM, MiMo Flash: Price and AA Index
Support
Hi! How can we help you?
Send a message and we'll get back to you soon.