API integration

Q: How do I quickly integrate?

A: Integration can be completed in as fast as 5 minutes:

Step 1: Obtain an API Key (See API Key Management for details)

Step 2: Install SDK

Python
pip install openai
Node.js
npm install openai

Step 3: Make an API call

from openai import OpenAI client = OpenAI(    api_key="sk-your-key",    base_url="https://api.maitoken/v1"  # Replace with platform address) response = client.chat.completions.create(    model="[model_name]",    messages=[        {"role": "system", "content": "You are an intelligent customer service assistant"},        {"role": "user", "content": "Hello"}    ])print(response.choices[0].message.content)

Step 4: Test using cURL

curl https://api.maitoken/v1/chat/completions \  -H "Authorization: Bearer sk-your-key" \  -H "Content-Type: application/json" \  -d '{"model":"[model_name]","messages":[{"role":"user","content":"Hello"}]}'

Q: Which programming languages/SDKs are supported?

A: Because of full compatibility with the OpenAI API protocol, all languages and SDKs that support OpenAI can be used directly:

  • Python (openai library)

  • Node.js / TypeScript (openai library)

  • Java (openai-java library)

  • Go (go-openai library)

  • C# / .NET

  • PHP / Ruby / Rust, etc.

  • Any programming language via direct HTTP REST API calls

Simply replace base_url with our endpoint address https://api.maitoken.net/v1; code modifications usually require fewer than 2 lines.

  • The API Key must be obtained from the MaiToken console and start with sk-

  • Ensure your account has sufficient balance

Q: How do I migrate from the official OpenAI API to your platform?

A:

Switch to MaiToken in under 5 minutes. No code rewriting needed—simply change the Base URL and API Key.

Before modification (Official OpenAI)
client = OpenAI(api_key="sk-openai-key")
After modification (Migrated to our platform)
client = OpenAI(    api_key="sk-your-our-key",           # Replace Key    base_url="https://api.maitoken/v1"  # Replace address)

Q: Do you support streaming output (SSE)?

A: Yes. Simply set stream=True

response = client.chat.completions.create(    model="[model_name]",    messages=[{"role": "user", "content": "Write a poem"}],    stream=True  # Enable streaming)for chunk in response:    if chunk.choices[0].delta.content:        print(chunk.choices[0].delta.content, end="")

Streaming output significantly reduces perceived latency for users (Time to First Token < 500ms), and is strongly recommended for conversational applications.

Q: Do you support Function Calling / Tool Calling?

A: Yes. Pass the tools parameter in the request:

tools = [{    "type": "function",    "function": {        "name": "get_weather",        "description": "Query weather for a specified city",        "parameters": {            "type": "object",            "properties": {                "city": {"type": "string", "description": "City name"}            },            "required": ["city"]        }    }}] response = client.chat.completions.create(    model="[model_supporting_FC]",    messages=[{"role": "user", "content": "How is the weather in Beijing today?"}],    tools=tools)

Note: Not all models support Function Calling.

Q: Do you support multimodal inputs (image input)?

Yes. Use a vision model (e.g., deepseek-v4-Vision), and pass images in messages:

messages = [{    "role": "user",    "content": [        {"type": "text", "text": "What is in this image?"},        {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}    ]}]
  • Supports both image URL and Base64 input methods

  • Image formats: Common formats supported (such as JPEG, PNG, etc.)

  • Maximum 1 image per single request

  • Images automatically consume input Tokens (calculated based on resolution)

Q: Do you support Embedding (vectorization) endpoints?

A: Yes. Used for RAG retrieval, semantic search, and related scenarios:

response = client.embeddings.create(    model="[model_D-Embed]",    input=["Hello world", "Hello World"])print(response.data[0].embedding)  # Vector array
  • Output dimensions: [768 / 1024 / 1536] (depends on model)

  • Batch input supported, up to 10 texts per single request

Q: What is the Base URL?

A: