Back to Blog

4SAPI Integration Guide: AI Model Aggregation API

Tutorials and Guides7535
4SAPI Integration Guide: AI Model Aggregation API

As large language models become part of everyday development workflows, many developers and teams need a flexible way to access different AI models through a unified API relay platform. 4SAPI is one such LLM API relay platform that allows users to connect to multiple model providers through API keys, model groups, and configurable endpoints.

This guide walks through the complete 4SAPI integration process, from account registration and balance top-up to API key creation, model selection, endpoint configuration, code integration, and common troubleshooting tips.

Whether you are building a chatbot, connecting an AI coding assistant, or integrating large language models into an internal application, this article can serve as a practical step-by-step reference.

1. Overall Integration Flow

The full setup process can be summarized in one simple workflow:

text
Register Account → Top Up Balance → Create API Key → Select Group → Set Quota / Expiration → Complete Setup → Call API

At the technical level, API access mainly consists of two key elements:

text
API = Base URL + API Key

A typical configuration looks like this:

text
Base URL: https://4sapi.com
API Key:  sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

However, one important detail must be emphasized:

The final API endpoint may vary depending on the model you want to call. Before integration, always check the technical documentation or the model details page to confirm whether the URL should include /v1 or /v1/chat/completions.

4SAPI technical documentation:

text
https://4sapi.apifox.cn/

2. Step One: Register and Top Up Your Account

2.1 Register an Account

First, visit the official 4SAPI website and create an account using your email address. In most cases, a domestic email address is sufficient, and no overseas phone number is required.

After registration, log in to the user console.

2.2 Add Account Balance

Go to the Console page and open Wallet Management from the left sidebar. From there, you can top up your balance based on your expected usage.

Make sure your account balance is greater than 0, otherwise API requests cannot be processed.

4SAPI supports payment methods such as Alipay and corporate bank transfer. It uses a pay-as-you-go pricing model and does not require a minimum spending threshold.

3. Step Two: Create an API Key

Creating an API key is the most important step in the entire integration process. The API key is your credential for calling all available models on the platform.

3.1 Add a New Token

In the left sidebar, open Key Management, then click Add Token.

3.2 Fill in Token Information

When creating a token, you need to configure several fields:

FieldDescriptionRecommendation
Token NameA custom name for this API keyUse the project name or usage scenario, such as my-chatbot or cursor-dev
GroupDifferent groups represent different resource channelsCheck model pricing in the model marketplace or consult customer support
Token QuotaThe maximum available budget for this keySet it based on your project budget
Expiration DateThe validity period of the API keyFor long-term projects, monthly or yearly expiration is recommended

After filling in the information, click Submit to generate the API key.

3.3 Save the API Key Immediately

The API key is usually displayed only once after creation.

Make sure to copy and store it immediately. If you lose the key, it cannot be recovered. You will need to create a new one.

3.4 Check API Key Details

After the key is created, you can view its details in the Key Management page, including:

text
Status
Remaining balance
Associated group
Creation time
Expiration date

4. Step Three: Select a Group and Model

4.1 What Is a Group?

In 4SAPI, different groups correspond to different resource channels. These groups may vary in terms of model coverage, stability, and response quality.

The main differences include:

text
Different upstream providers
Different supported model lists
Different stability levels
Different response quality under the same model name

For most users, the recommended approach is to select the group with the best cost-performance ratio based on actual usage needs. If you are not sure which group to choose, you can contact customer support for assistance.

4.2 Check the Model Marketplace

Open the Model Marketplace page in the console. This page shows available models under different groups, along with their corresponding usage costs.

Before calling a model, check the following information carefully:

text
Model name
Supported group
Pricing rules
Supported API endpoint
Request format

4.3 View Model Details

Click the model name to open its detail page. The detail page usually includes:

text
Model introduction
Recommended use cases
Billing rules
Supported API endpoints
Request format requirements

This information is important because different models may use different endpoint paths.

4.4 Copy the Exact Model Name

The model name must be exactly the same as the one registered on the platform.

For example:

text
Correct:

claude-sonnet-4-5-20250929
gpt-5.3
deepseek-v4

Incorrect examples:

text
claude-sonnet-4.5
Claude Sonnet 4.5
gpt5.3

Even a missing hyphen, wrong capitalization, or missing date suffix may cause the request to fail.

The safest method is to copy the model name directly from the Model Marketplace instead of typing it manually.

5. Step Four: Get the API Relay Address

On the right side of the console page, you can find different site or node information provided by 4SAPI.

The platform may provide multiple access nodes. You can select the node with the lowest latency based on your network environment.

In most cases, the commonly used base URL is:

text
https://4sapi.com

But the final endpoint still depends on the model and the software or SDK you are using.

6. Step Five: Confirm the API Endpoint and Model Name

This is one of the most common sources of integration errors.

The API URL is not always fixed. Different models or third-party tools may require different URL formats.

6.1 Common URL Formats

URL FormatTypical Use Case
https://4sapi.comBasic endpoint for some models or tools
https://4sapi.com/v1Common OpenAI-compatible API base URL
https://4sapi.com/v1/chat/completionsFull endpoint required by some third-party tools

To confirm the correct endpoint, open the target model in the Model Marketplace and check its supported API endpoint. You can also refer to the technical documentation:

text
https://4sapi.apifox.cn/

6.2 Required Configuration Information

Before calling any model, make sure you have confirmed these three items:

text
API Base URL → https://4sapi.com/v1
API Key      → sk-xxxxxxxxxxxxxxxxxxxxxxxx
Model Name   → claude-sonnet-4-5-20250929

If any of these three values is incorrect, the request may fail.

7. Step Six: Integrate with Code

7.1 Prepare the Environment

For Python projects, make sure your Python version is 3.8 or later.

bash
python --version

Install the OpenAI SDK:

bash
pip install "openai>=1.0.0"

If you need to use the Anthropic native format, install the Anthropic SDK:

bash
pip install "anthropic>=0.30.0"

8. Method One: OpenAI-Compatible Format

For most users, the OpenAI-compatible format is the easiest integration method.

You only need to set the base_url to the 4SAPI endpoint and use your 4SAPI API key for authentication.

python
from openai import OpenAI

client = OpenAI(
    base_url="https://4sapi.com/v1",
    api_key="sk-your-4sapi-api-key"
)

response = client.chat.completions.create(
    model="claude-sonnet-4-5-20250929",
    messages=[
        {
            "role": "system",
            "content": "You are a professional Python development assistant."
        },
        {
            "role": "user",
            "content": "Write a thread-safe LRU cache implementation in Python."
        }
    ],
    temperature=0.7,
    max_tokens=4096
)

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

In this example:

text
base_url  → The API endpoint confirmed from the model page
api_key   → The token created in Key Management
model     → The exact model name copied from the Model Marketplace

9. Method Two: Anthropic Native Format

If you want to call Claude models using the Anthropic native message format, you can use the Anthropic SDK.

python
from anthropic import Anthropic

client = Anthropic(
    api_key="sk-your-4sapi-api-key",
    base_url="https://4sapi.com/v1",
    timeout=120
)

response = client.messages.create(
    model="claude-sonnet-4-5-20250929",
    max_tokens=8192,
    system="You are a professional technical documentation writer. Output in Markdown format.",
    messages=[
        {
            "role": "user",
            "content": "Summarize the core updates of React 19."
        }
    ]
)

print(response.content[0].text)

Claude models may also support the native /v1/messages endpoint. For exact configuration details, refer to the Claude native API documentation provided by the platform.

10. Replace the API Address in Existing Projects

If your existing project already uses the official OpenAI API, migration is usually simple.

In many cases, you only need to replace the original OpenAI API address:

text
https://api.openai.com/

with:

text
https://4sapi.com

The rest of the code may remain unchanged if the project uses an OpenAI-compatible request format.

However, you should still verify the exact endpoint required by the model. Some projects require an API base URL, while others require a complete endpoint such as:

text
https://4sapi.com/v1/chat/completions

11. Configure Third-Party Software or Platforms

When configuring 4SAPI in third-party AI tools, coding assistants, or development platforms, the required URL format may vary.

Common formats include:

text
https://4sapi.com
https://4sapi.com/v1
https://4sapi.com/v1/chat/completions

Some tools ask for an API Base URL, while others ask for the full Chat Completions endpoint.

If the connection fails, check the tool’s custom API configuration guide and compare it with the endpoint shown in the 4SAPI Model Marketplace.

12. Step Seven: Verify the Integration

After completing the configuration, run a simple test request.

If the terminal returns a normal model response, the integration is successful.

12.1 Connectivity Test

python
response = client.chat.completions.create(
    model="claude-sonnet-4-5-20250929",
    messages=[
        {
            "role": "user",
            "content": "ping"
        }
    ]
)

print("Connection successful" if response else "Connection failed")

12.2 Long Text Test

This test helps verify whether your timeout and token settings are reasonable.

python
long_prompt = "Please analyze the following code in detail:\n" + "def example():\n    pass\n" * 200

response = client.chat.completions.create(
    model="claude-sonnet-4-5-20250929",
    messages=[
        {
            "role": "user",
            "content": long_prompt
        }
    ],
    max_tokens=4096
)

print(f"Long text test passed. Returned {len(response.choices[0].message.content)} characters.")

12.3 Concurrency Test

For production scenarios, you should also test concurrent requests.

For example, send five requests at the same time. If all requests return successfully, the basic concurrency test is passed.

13. Common Integration Issues and Solutions

IssuePossible CauseSolution
Request failsMissing /v1 in the URLCheck the correct endpoint in the Model Marketplace
404 errorWrong endpoint pathSome models do not require /chat/completions
401 authentication errorWrong credential usedUse the API key from Key Management, not the login password
Model not foundIncorrect model nameCopy the model name directly from the Model Marketplace
Insufficient balanceAccount balance is 0Top up your account in Wallet Management
Third-party tool cannot connectURL format mismatchTry /v1, /v1/chat/completions, or the base URL according to the tool’s requirements

14. Practical Integration Checklist

Before using 4SAPI in a real project, go through the following checklist:

text
Account has been registered
Account balance is greater than 0
API key has been created and saved
Correct group has been selected
Target model name has been copied exactly
API endpoint has been confirmed from the model page or documentation
SDK has been installed
Connectivity test has passed
Long text and timeout tests have been completed
Third-party tool URL format has been verified

This checklist can help avoid most common configuration errors.

15. Final Thoughts

4SAPI provides a practical relay solution for developers who need to access multiple large language models through API calls. The core integration process is not complicated, but several details require careful attention, especially the API endpoint, model name, group selection, account balance, and API key management.

For first-time users, the safest workflow is:

text
Create account
Top up balance
Create and save API key
Select model and group
Copy the exact model name
Confirm the endpoint
Run a simple test request
Then integrate into your actual project

Once these steps are completed, developers can connect 4SAPI to Python scripts, backend services, AI coding tools, chatbot systems, or other applications that support custom LLM API configuration.

This article uses 4SAPI as the example platform in the LLM API relay series. Developers can evaluate the platform based on their own model requirements, budget, stability needs, and integration environment.

Tags:4SAPILLM APIAPI RelayModel Aggregation

Recommended reading

Explore more frontier insights and industry know-how.