Quick Start

OpenAI-Compatible API tutorial: Base URL, SDKs and request verification

OpenAI-Compatible API tutorial: configure the Base URL, API key and live model ID with curl, Python and Node.js, verify the model list and a minimal request, and troubleshoot 401, model not found and /v1/v1 errors.

Updated on 2026-10-20Verified 2026-09-09Estimated reading time: 8 minutesFor OpenAI Compatible API
Configuration fields were checked against public documentation. Models, prices, and capabilities can change; verify current values in the console and live API responses.
Topic: What Is an OpenAI-Compatible API? Scope and Limits

The value of OpenAI Compatible API is to allow existing SDKs, scripts and tools to connect different models through a unified protocol. There is usually no need to rewrite business logic when migrating, the focus is on confirmation Base URL, API Key, model ID and API type.

Direct answer

To integrate an OpenAI-compatible API, first set the Base URL to the address in the provider's documentation, then use the same API key to request /v1/models, copy the real model ID returned, and finally send a stream: false short request. If the final URL contains /v1/v1, returns HTML, or the model ID from the list is unavailable, fix the Base URL, authentication, or model permission before testing SSE and tool calls.

The OpenAI SDK base URL for Link is https://www.aifast.link/v1. Claude Code uses https://www.aifast.link and sends Messages requests to /v1/messages. These fields use different path-joining rules. An image-generation model is not automatically a chat or Codex coding model.

Check the Link model directory, then query accessible models with your own key. Plan users should also check that the key group matches the plan scope. After one successful text request, verify its billing source in the usage log before enabling retries or batch requests.

Review Link funding and monthly-plan rules

How do you integrate and test an OpenAI-compatible API?

Use the table below to prepare your configuration and verification evidence, then run the curl, Python or Node.js examples.

Check first Evidence to retain Next step after passing
Base URL The final request URL contains exactly one /v1 Request /v1/models
API Key Authorization: Bearer from the same platform Copy the real model ID returned
Model ID data[].id matches the models visible to the current account Send a short stream: false Request
Protocol capabilities Status code, response model、usage and completion state Test SSE, tool calls, and Responses separately

This table defines only the verification order; it does not mean that any platform's models or advanced capabilities are necessarily compatible.

How should I fill in the Base URL of OpenAI Compatible API?

The OpenAI SDK appends model-list and chat endpoints to the Base URL. A common version path is /v1, the complete example is https://www.aifast.link/v1. If the client explicitly appends the version path, enter only the domain. Judge by the final request URL in diagnostic logs, not by the settings-field label. If the final URL contains the duplicate path /v1/v1, the version path has been appended twice. A webpage homepage response is not a valid API response.

Open the Base URL Inspector

How do you test an OpenAI-compatible API?

Do not rely on the HTTP status alone. Compare the results below to identify the failing stage before adding more parameters.

Observed result What can be explained Next step
HTTP 200 with an HTML body The request may have reached a web page rather than an API endpoint Check the final URL and response Content-Type
401 JSON This request did not pass authentication Check the key issuer, authentication header and client environment variables
Model listing succeeds, but a short request fails A readable model list does not establish access to that model Save the error type and check the exact model ID, group and quota
A short request succeeds, but SSE or tools fail Basic text works; the additional capability has not passed Test the protocol required by your client separately

For a sample of protocol and behavior signals, run the Model Quality Check; for the full capability checklist, see API compatibility checks. These results do not certify the model vendor or establish a long-term SLA.

Check before you start

Prepare the following three items:

  1. API Key created in AIFast console.
  2. API base address https://www.aifast.link/v1.
  3. The real model ID shown in the console model square.

API Keys are only displayed in full when they are created. Don't write it into public repositories, front-end code, screenshots, or chat logs.

Configuration steps

1. First query the model list

Execute in terminal:

curl https://www.aifast.link/v1/models \
  -H "Authorization: Bearer $AIFAST_API_KEY"

If successful the return contains data An array of model list responses, indicating that domain name resolution, HTTPS, and authentication links are basically normal. if return 401, check the Key first; if an HTML page is returned, it is usually because the Base URL is written incorrectly or the request does not enter the API route.

Send one minimal chat request with curl

This is a request example to run yourself, not a completed live model test. Set AIFAST_API_KEY securely on your computer and replace YOUR_MODEL_ID with a text model available to the same key and explicitly supporting Chat Completions. Execution may incur charges. Send just one short request without automatic retries; do not run batches before confirming access.

: "${AIFAST_API_KEY:?Set AIFAST_API_KEY locally before running}"
curl --request POST \
  --connect-timeout 10 --max-time 30 \
  --silent --show-error --include \
  https://www.aifast.link/v1/chat/completions \
  --header "Authorization: Bearer ${AIFAST_API_KEY}" \
  --header "Content-Type: application/json" \
  --data-raw '{"model":"YOUR_MODEL_ID","messages":[{"role":"user","content":"Reply with OK only."}],"stream":false}'

Inspect the HTTP status and Content-Type, then choices, message, finish_reason and usage in the JSON. HTTP 200 is only one necessary check: an error object, empty choices or missing expected text is not success. Record missing usage rather than treating it as zero. This request tests only Chat Completions, not Responses, tool calls or every model.

After a timeout or disconnect, check usage logs before retrying. A client timeout does not prove that processing or billing stopped. Support does not need your complete key. Remove Authorization, cookies, customer prompts and personal information before sharing diagnostics.

How do Chat Completions, Responses and Messages differ?

OpenAI compatibility refers to a particular API shape, not automatic support for every client, model or feature. Choose an endpoint for your task and verify each row separately. These are request structures, not guarantees of account capabilities.

Where the error appears Final path Core request fields Relevant check
Standard OpenAI SDK chat /v1/chat/completions model、messages The minimal curl and SDK requests on this page
Codex custom provider /v1/responses model、input Codex setup and Responses checks
Native Claude Code protocol /v1/messages model、messages、max_tokens Messages, SSE and tool-result checks

A listed model ID is not proof that every endpoint supports it. Native Gemini generateContent is not an alias for these request bodies and needs its own protocol configuration.

See Link Gemini protocols and group access

Continue with SDK setup

2. Using the Python SDK

Install SDK:

python -m pip install --upgrade openai

Put Key into environment variables:

export AIFAST_API_KEY="your_API_Key"

Minimal call example:

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["AIFAST_API_KEY"],
    base_url="https://www.aifast.link/v1",
    max_retries=0,
    timeout=30.0,
)

response = client.chat.completions.create(
    model="YOUR_MODEL_ID",
    messages=[
        {"role": "user", "content": "Explain what hint caching is in three sentences。"}
    ],
)

print(response.choices[0].message.content)

will YOUR_MODEL_ID Replace with the real model ID in the model square and do not fill in the card title, Chinese alias or manufacturer name.

3. Use the Node.js SDK

npm install openai
export AIFAST_API_KEY="your_API_Key"
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.AIFAST_API_KEY,
  baseURL: "https://www.aifast.link/v1",
  maxRetries: 0,
  timeout: 30_000,
});

const response = await client.chat.completions.create({
  model: "YOUR_MODEL_ID",
  messages: [
    { role: "user", content: "list API Five configurations you need to check before going online。" },
  ],
});

console.log(response.choices[0].message.content);

4. Do not repeat splicing /v1

Different clients handle Base URLs differently:

client fields It is recommended to fill in
Explicitly request Base URL https://www.aifast.link/v1
The client will automatically add /v1 https://www.aifast.link
Complete request address Fill in the specific API according to the client's requirements

If it appears in the log /v1/v1/chat/completions, indicating that the client and configuration are each added once. /v1.

FAQ

Return 401 Unauthorized

  • Are there any spaces or quotation marks before and after Key?
  • Whether a Key that has been deleted, expired, or belongs to another account has been misused.
  • Whether the request header is Authorization: Bearer YOUR_KEY.

Return model not found

  • call first /v1/models Get the real model ID.
  • Do not use the web page display name as the API model name.
  • Confirm whether the model is open to the current account.

Streaming output interrupted

First turn off the streaming mode and make a short request. If non-streaming requests are OK, then check client read timeouts, proxy buffering, and network connectivity instead of replacing the model directly.

Next step

After the first request is successful, streaming output, retries, timeouts, logs and model routing are gradually added. Don't plug in all advanced parameters at once without validating the underlying call.

View 401, 429, 502 API error troubleshooting, or go to AIFast model catalog to confirm which models are currently available.

To verify AIFast's current domains, Base URL, or platform statements, return to platform facts, official entry points, and verification limitsand review the evidence type and latest verification date.

Verification on 11 October 2026: separate authentication from model inference

Two unauthenticated GET requests were made to the public Link endpoints: /api/status returned 200 JSON; /v1/models returned 401 JSON with error type new_api_error. The 401 is the expected authentication rejection in this control, not evidence that a model is offline. Neither result proves that authenticated inference, streaming or tool calls succeed.

Run the unauthenticated control below first. If it returns HTML, a challenge page or a timeout, diagnose the network and API path before passing the response to an SDK as model JSON. Then set a separate limited key on your own computer and use the examples above to test the model list and a short request.

curl --connect-timeout 10 --max-time 30 -sS \
  -o aifast-auth-check.json -w "%{http_code}\n" \
  https://www.aifast.link/v1/models

What to record in a minimal migration test

Record the installed SDK version using python -m pip show openai or npm ls openai. Keep the key, model ID, group and short prompt fixed while changing only the Base URL. Disable automatic retries and set a 30-second timeout for the initial diagnostic. Adjust and record the timeout separately for slower models so repeated requests are not mistaken for one call.

For a successful sample, record the final endpoint, HTTP status, returned model, finish reason, usage, final charge and billing source in the Link usage log. A reservation is not the final charge. A text response does not prove support for all SSE, Responses, image or agent features. Remove keys, customer prompts and personal information from public records and screenshots.

This section reports only the authentication-endpoint checks above and the migration acceptance method. It does not claim successful paid inference or SDK calls that were not performed.

FAQ

How should you fill in an OpenAI-compatible API URL?

First confirm whether the client appends /v1 automatically. If it does not, the Base URL usually includes /v1; if it does, use the domain root. Use request logs as the final authority and do not allow the URL to become /v1/v1.

How do you test an OpenAI-compatible API?

Use the same key to request /v1/models, then send a short non-streaming request with a real model ID. After it succeeds, test SSE, tool calls, and usage fields separately. You can use the Base URL checker and gateway test; do not judge full compatibility from HTTP 200 alone.

How do you list models from an OpenAI-compatible API?

Use the target platform's API key to request /v1/models and copy the real id from the returned data array. A card title, Chinese alias, or vendor name cannot directly replace the model ID.

Source checked

Reference and Check Sources

Next step

Test the current API before fixing, migrating, or creating a test key

Use a temporary, limited key to inspect model declarations, token fields, SSE, and tool calls. Review current models and pricing only when you need a replacement API.

Model Quality CheckModel PricingCreate Account