---
title: "What Is an AI API? Base URL, API Key, and Token Billing Explained"
description: "A plain-English guide to what an AI API is: base URL, API key, requests and responses, token billing, why dev tools need an API, and three ways to connect."
url: https://cdnping.org/en/blog/what-is-ai-api-beginner
language: en
published: 2026-11-18
category: "AI concepts"
tags: ["AI API","API key","beginner guide","token billing","access options"]
source: cdnping.org
license: Free to quote and summarize with a link to the url above.
---
# What Is an AI API? Base URL, API Key, and Token Billing Explained

An AI API is an interface that lets a program call a large language model directly: your program sends a request in an agreed format, and the server returns the text the model generated. It needs no web UI and no browser login. Instead, a secret called an API key proves who is calling, and you pay by usage. If you have just started wondering what an AI API is, here is the whole idea in terms of mailing letters.

## What is an AI API, exactly? A mail analogy

Think of a model service as a company that writes back:

- The **base URL** is the company's mailing address. Requests have to go there, and a letter sent to the wrong address gets no reply.
- The **API key** is your customer number plus your signature. The company uses it to recognize you and bill the usage to your account.
- The **request** is the letter you write: which model to use, your question, and some parameters (such as a cap on answer length).
- The **response** is the reply: the generated content, plus how many tokens the call used.

A web chat does the same thing; the browser just writes, sends, and opens the letters for you. An API hands those steps to your program, which is why scripts, editor plugins, and command-line tools can use models "automatically."

## What is an API key, and why guard it?

An API key is a long string of characters, usually starting with a provider-specific prefix; check each provider's official docs for the exact format. Whoever holds it can make calls in your name and run up charges. A few basics:

1. Keep it out of code repositories, and don't paste it into chat groups or screenshots. Use environment variables or the tool's own key settings.
2. Create one key per purpose, so you can revoke just one if something goes wrong.
3. Check the usage page regularly, and revoke the key right away if you see calls you don't recognize.

If a key has already leaked, see [OpenAI API key leaked: revoke it, check usage, and prevent a repeat](/en/blog/openai-api-key-leaked-response). Whether you may share a key with others depends on the provider's terms; see [Does sharing an OpenAI API key with others violate the terms?](/en/blog/openai-terms-sharing-api-keys)

## Why is billing per token, and how is one call priced?

A token is the smallest unit in which a model measures text. A Chinese character or a fragment of an English word is roughly one to a few tokens, and the exact split varies by model. A bill usually has two parts: what you send counts as input, and what the model generates counts as output. The two have different unit prices, and output is typically more expensive.

So asking one question with a big chunk of code attached costs very differently from asking a one-line question, and agent tasks that repeatedly read and edit files can burn a lot of tokens. To break a single call's bill into line items, read [How token billing works: itemizing one LLM API call](/en/blog/llm-token-billing-explained).

## Why do developer tools need an API instead of a web account?

This is where beginners get stuck most often. A web subscription (a paid membership from a given vendor) covers chatting on the vendor's own website or app, and its billing and quota belong to that product. Tools such as Claude Code, Codex, Cherry Studio, and Cline instead need a base URL and a key, and they send the requests themselves.

The two are usually separate account systems with quotas that do not carry over. [ChatGPT Plus vs. the OpenAI API: separate accounts, billing, and quotas](/en/blog/chatgpt-plus-vs-openai-api-difference) goes into this. Whether a particular official tool supports signing in with a subscription or entering a key is determined by that tool's official docs.

## What are the three ways to connect?

| Path | How you get a base URL and key | Good for | Watch out for |
| --- | --- | --- | --- |
| Direct from the provider | Sign up on the model vendor's developer platform, add funds, create a key | Wanting to work with one specific vendor | Supported regions and payment methods differ by vendor; follow the official docs |
| Cloud platform | Enable it through the cloud vendor's model service | Your company already uses that cloud | Setup steps and billing follow the cloud vendor's docs |
| Aggregation gateway | Sign up with the gateway and use the address and key it gives you | Wanting one entry point to switch between several models | Check whether it is officially authorized and how it handles your data |

Behind all three paths, the format is mostly compatible with one of two interfaces, OpenAI's or Anthropic's, so in a tool you often only need to change the address and key. For the mechanics, see [How one API key can call models from several providers: interface compatibility and gateways](/en/blog/one-api-key-multiple-models).

## How do you confirm it is really connected?

Whichever path you take, start with a minimal check:

1. In the tool's settings, find the "Base URL" and "API Key" fields and fill in each one.
2. Send a very short message, such as "hello," and confirm you get a reply.
3. Go back to the provider's usage page, confirm the call was recorded, and check that the token count looks reasonable.
4. If you get an error, look at the status code first: 401 is most often a bad key, 429 is most often rate limiting or a quota problem, and 5xx is most often a server-side issue. For the full list, see [LLM API error code cheatsheet: what 400 to 529 mean and which to retry](/en/blog/ai-api-error-codes-400-to-529-cheatsheet).
5. If you suspect the network, use cdnping's [online speed test](/en) to measure first-connection time and round trip to each API, or check [Is it down?](/en/down) to see whether a service is currently having an outage. For background, see [How to read AI API latency from mainland China](/en/learn/ai-api-latency-china).

## Not sure which path to pick? Where AGI Plan fits

Say you want to try tools like Claude Code or Codex but don't have an overseas credit card. An aggregation gateway is one option. AGI Plan is a commercial partner of cdnping. Here we only describe its public details, and whether it suits you is your call:

- Monthly subscription, paid in RMB, no overseas credit card needed.
- One subscription can switch between several capability groups, and it is compatible with both the OpenAI and Anthropic interface formats.
- With tools like Claude Code and Codex, you only change one base URL. Claude Code needs no Claude account, and Codex needs no ChatGPT account.
- It states clearly that it is not an officially authorized channel. Some models are marked as available only outside mainland China; see the [AGI Plan models page](https://agiplan.dev/models) for specifics.

Whether it fits depends on your budget and usage habits. To compare subscriptions and APIs first, read [Subscription or API for beginners: choose by use case](/en/blog/subscription-or-api-for-beginners).

## What to do next

- Not sure whether you want the web, an app, or an API: start with [How to start using AI: web, app, or API](/en/blog/ai-beginner-how-to-start-using-ai).
- Want to try an aggregation gateway directly: open the [AGI Plan getting-started guide](https://agiplan.dev/startup) and follow its three steps: sign up with an email, pick a plan and create a key, and change one setting.
- Want to go direct to the provider first: read that vendor's developer docs, register as it requires, and comply with its terms of service and local regulations.
