Ling-AntDigital
This document describes how to call the Ling series model inference service directly provided by AntDigital on the Alibaba Cloud Model Studio platform.
ImportantThe features described in this topic are available only in the China (Beijing) region. To call the model, you must obtain and configure an API key in the China (Beijing) region.
Activate the service
- Go to the Model Studio console, search for Ling, find the antdigital/Ling-3.1-flash model card, and click Activate Now.
- In the pop-up window, confirm the activation and authorization.
After you complete these steps, you can call the AntDigital Ling model service.
Getting started
Prerequisites- You have obtained and configured an API key.
- If you call the service using a software development kit (SDK), you must install the SDK.
antdigital/Ling-3.1-flash is a hybrid thinking model directly provided by AntDigital. It supports only text input and runs in thinking mode by default:
- Thinking mode (default, or
enable_thinking: true): The model outputs its reasoning process (reasoning_content). - Non-thinking mode (
enable_thinking: false): The model directly outputs the result without the reasoning process.
You can use the preserve_thinking parameter to pass the thinking process in multi-turn conversations. For more information, see Multi-turn conversation.
The following example calls antdigital/Ling-3.1-flash in thinking mode with streaming output.
Note
enable_thinkingis not a standard OpenAI parameter. In the OpenAI Python SDK, pass it viaextra_body. In the Node.js SDK, pass it as a top-level parameter.- For streaming output,
include_usageinstream_optionssupports onlytrue. Passingfalsereturns an error.
Python
from openai import OpenAI
import os
# Initialize the OpenAI client
client = OpenAI(
# If you have not configured an environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
# The following URL is for the China (Beijing) region. Replace {WorkspaceId} with your Model Studio workspace ID. URLs vary by region.
base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
messages = [{"role": "user", "content": "Which is larger, 9.9 or 9.11?"}]
completion = client.chat.completions.create(
model="antdigital/Ling-3.1-flash",
messages=messages,
stream=True,
stream_options={
"include_usage": True
},
# Thinking mode is enabled by default. To disable it, set enable_thinking to False
extra_body={"enable_thinking": True}
)
reasoning_content = "" # Full chain-of-thought
answer_content = "" # Full response
is_answering = False # Whether the response phase has started
print("\n" + "=" * 20 + "Chain-of-thought" + "=" * 20 + "\n")
for chunk in completion:
if not chunk.choices:
print("\n" + "=" * 20 + "Token usage" + "=" * 20 + "\n")
print(chunk.usage)
continue
delta = chunk.choices[0].delta
# Collect only the thinking content
if hasattr(delta, "reasoning_content") and delta.reasoning_content is not None:
if not is_answering:
print(delta.reasoning_content, end="", flush=True)
reasoning_content += delta.reasoning_content
# When content is received, start the response
if hasattr(delta, "content") and delta.content:
if not is_answering:
print("\n" + "=" * 20 + "Full response" + "=" * 20 + "\n")
is_answering = True
print(delta.content, end="", flush=True)
answer_content += delta.content
Node.js
import OpenAI from "openai";
import process from 'process';
// Initialize the OpenAI client
const openai = new OpenAI({
// If you have not configured an environment variable, replace the following line with your Model Studio API key: apiKey: "sk-xxx"
apiKey: process.env.DASHSCOPE_API_KEY,
// The following URL is for the China (Beijing) region. Replace {WorkspaceId} with your Model Studio workspace ID. URLs vary by region.
baseURL: 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1'
});
let reasoningContent = ''; // Full chain-of-thought
let answerContent = ''; // Full response
let isAnswering = false; // Whether the response phase has started
async function main() {
try {
const messages = [{ role: 'user', content: 'Which is larger, 9.9 or 9.11?' }];
const stream = await openai.chat.completions.create({
model: 'antdigital/Ling-3.1-flash',
messages,
stream: true,
stream_options: {
include_usage: true
},
// Thinking mode is enabled by default. To disable it, set enable_thinking to false
enable_thinking: true
});
console.log('\n' + '='.repeat(20) + 'Chain-of-thought' + '='.repeat(20) + '\n');
for await (const chunk of stream) {
if (!chunk.choices?.length) {
console.log('\n' + '='.repeat(20) + 'Token usage' + '='.repeat(20) + '\n');
console.log(chunk.usage);
continue;
}
const delta = chunk.choices[0].delta;
// Collect only the thinking content
if (delta.reasoning_content !== undefined && delta.reasoning_content !== null) {
if (!isAnswering) {
process.stdout.write(delta.reasoning_content);
}
reasoningContent += delta.reasoning_content;
}
// When content is received, start the response
if (delta.content !== undefined && delta.content) {
if (!isAnswering) {
console.log('\n' + '='.repeat(20) + 'Full response' + '='.repeat(20) + '\n');
isAnswering = true;
}
process.stdout.write(delta.content);
answerContent += delta.content;
}
}
} catch (error) {
console.error('Error:', error);
}
}
main();
curl
# The following URL is for the China (Beijing) region. Replace {WorkspaceId} with your Model Studio workspace ID. URLs vary by region.
curl -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "antdigital/Ling-3.1-flash",
"messages": [
{
"role": "user",
"content": "Which is larger, 9.9 or 9.11?"
}
],
"stream": true,
"stream_options": {
"include_usage": true
},
"enable_thinking": true
}'
Other features
| Feature | Supported | Notes |
|---|---|---|
| Multi-turn conversation | Supported | — |
| Function calling | Supported | Supports streaming tool call arguments through tool_stream. Does not support parallel_tool_calls |
| Partial mode | Supported | — |
| Context cache | Supported | Implicit cache. Input tokens that hit the cache are billed at 20% of the input price |
| Structured output | Supported | response_format supports only {"type": "json_object"}. json_schema is not supported |
| Web search | Unsupported | — |
| Multimodal input | Unsupported | Supports only text input |
antdigital/Ling-3.1-flash does not support the following parameters: thinking_budget, reasoning_effort, parallel_tool_calls, seed, logprobs, top_logprobs, enable_code_interpreter, enable_search, search_options, and skill.
Models and pricing
| Model | Description |
|---|---|
| antdigital/Ling-3.1-flash | Hybrid thinking model with thinking mode enabled by default. Context length: 1,048,576 tokens |
For model pricing and rate limits, see Model pricing and Rate limits.
You are charged based on the input and output tokens of the model.
In thinking mode, the chain-of-thought is billed as output tokens.
Error codes
If a model call fails and returns an error message, see Error codes for troubleshooting.