Skip to main content

Présentation des services de modèles

Accédez aux API de modèles de texte, de vision, de voix, omni et d’embeddings, avec prise en charge des appels en ligne, de la planification de l’inférence et de l’entraînement des modèles.

Démarrage rapide

Appels API compatibles OpenAI/Anthropic

curl "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/responses" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen4-max",
    "input": "Who are you?"
  }'
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["DASHSCOPE_API_KEY"],
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)
response = client.responses.create(
    model="qwen4-max",
    input="Who are you?",
)
print(response.output_text)
import OpenAI from "openai";

const client = new OpenAI({
    apiKey: process.env.DASHSCOPE_API_KEY,
    baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
});
const response = await client.responses.create({
    model: "qwen4-max",
    input: "Who are you?",
});
console.log(response.output_text);
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.Response;
import com.openai.models.responses.ResponseCreateParams;

public class Main {
    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.builder()
            .apiKey(System.getenv("DASHSCOPE_API_KEY"))
            .baseUrl("https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1")
            .build();
        ResponseCreateParams params = ResponseCreateParams.builder()
            .model("qwen4-max")
            .input("Who are you?")
            .build();
        Response response = client.responses().create(params);
        response.output().stream()
            .flatMap(item -> item.message().stream())
            .flatMap(message -> message.content().stream())
            .flatMap(content -> content.outputText().stream())
            .forEach(text -> System.out.println(text.text()));
    }
}
package main

import (
    "context"
    "fmt"
    "os"

    "github.com/openai/openai-go/v3"
    "github.com/openai/openai-go/v3/option"
    "github.com/openai/openai-go/v3/responses"
)

func main() {
    client := openai.NewClient(
        option.WithAPIKey(os.Getenv("DASHSCOPE_API_KEY")),
        option.WithBaseURL("https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"),
    )
    response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
        Model: "qwen4-max",
        Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Who are you?")},
    })
    if err != nil {
        panic(err)
    }
    fmt.Println(response.OutputText())
}
#pragma warning disable OPENAI001

using System;
using System.ClientModel;
using OpenAI.Responses;

ResponsesClient client = new(
    new ApiKeyCredential(Environment.GetEnvironmentVariable("DASHSCOPE_API_KEY")!),
    new ResponsesClientOptions
    {
        Endpoint = new Uri("https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1")
    });
ResponseResult response = client.CreateResponse(new CreateResponseOptions
{
    Model = "qwen4-max",
    InputItems = { ResponseItem.CreateUserMessageItem("Who are you?") }
});
Console.WriteLine(response.GetOutputText());
require "openai"

client = OpenAI::Client.new(
  api_key: ENV.fetch("DASHSCOPE_API_KEY"),
  base_url: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
)
response = client.responses.create(
  model: "qwen4-max",
  input: "Who are you?"
)
puts response.output_text
curl "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen4-max",
    "messages": [{"role": "user", "content": "Who are you?"}]
  }'
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["DASHSCOPE_API_KEY"],
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)
response = client.chat.completions.create(
    model="qwen4-max",
    messages=[{"role": "user", "content": "Who are you?"}]
)
print(response.choices[0].message.content)
import OpenAI from "openai";

const client = new OpenAI({
    apiKey: process.env.DASHSCOPE_API_KEY,
    baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
});
const response = await client.chat.completions.create({
    model: "qwen4-max",
    messages: [{ role: "user", content: "Who are you?" }]
});
console.log(response.choices[0].message.content);
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.chat.completions.ChatCompletion;
import com.openai.models.chat.completions.ChatCompletionCreateParams;

public class Main {
    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.builder()
            .apiKey(System.getenv("DASHSCOPE_API_KEY"))
            .baseUrl("https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1")
            .build();
        ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
            .model("qwen4-max")
            .addUserMessage("Who are you?")
            .build();
        ChatCompletion response = client.chat().completions().create(params);
        System.out.println(response.choices().get(0).message().content().orElse(""));
    }
}
package main

import (
    "context"
    "fmt"
    "os"

    "github.com/openai/openai-go/v3"
    "github.com/openai/openai-go/v3/option"
)

func main() {
    client := openai.NewClient(
        option.WithAPIKey(os.Getenv("DASHSCOPE_API_KEY")),
        option.WithBaseURL("https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"),
    )
    response, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
        Model: "qwen4-max",
        Messages: []openai.ChatCompletionMessageParamUnion{
            openai.UserMessage("Who are you?"),
        },
    })
    if err != nil {
        panic(err)
    }
    fmt.Println(response.Choices[0].Message.Content)
}
using System;
using System.ClientModel;
using OpenAI;
using OpenAI.Chat;

ChatClient client = new(
    model: "qwen4-max",
    credential: new ApiKeyCredential(Environment.GetEnvironmentVariable("DASHSCOPE_API_KEY")!),
    options: new OpenAIClientOptions
    {
        Endpoint = new Uri("https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1")
    });
ChatCompletion response = client.CompleteChat("Who are you?");
Console.WriteLine(response.Content[0].Text);
require "openai"

client = OpenAI::Client.new(
  api_key: ENV.fetch("DASHSCOPE_API_KEY"),
  base_url: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
)
response = client.chat.completions.create(
  model: "qwen4-max",
  messages: [{role: "user", content: "Who are you?"}]
)
puts response.choices.first.message.content
curl "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1/messages" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen4-max",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Who are you?"}]
  }'
import os
from anthropic import Anthropic

client = Anthropic(
    api_key=os.environ["DASHSCOPE_API_KEY"],
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
)
response = client.messages.create(
    model="qwen4-max",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Who are you?"}]
)
for block in response.content:
    if block.type == "text":
        print(block.text)
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
    apiKey: process.env.DASHSCOPE_API_KEY,
    baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
});
const response = await client.messages.create({
    model: "qwen4-max",
    max_tokens: 1024,
    messages: [{ role: "user", content: "Who are you?" }]
});
for (const block of response.content) {
    if (block.type === "text") console.log(block.text);
}
import com.anthropic.client.AnthropicClient;
import com.anthropic.client.okhttp.AnthropicOkHttpClient;
import com.anthropic.models.messages.Message;
import com.anthropic.models.messages.MessageCreateParams;

public class Main {
    public static void main(String[] args) {
        AnthropicClient client = AnthropicOkHttpClient.builder()
            .apiKey(System.getenv("DASHSCOPE_API_KEY"))
            .baseUrl("https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic")
            .build();
        MessageCreateParams params = MessageCreateParams.builder()
            .model("qwen4-max")
            .maxTokens(1024L)
            .addUserMessage("Who are you?")
            .build();
        Message response = client.messages().create(params);
        response.content().stream()
            .flatMap(block -> block.text().stream())
            .forEach(text -> System.out.println(text.text()));
    }
}
package main

import (
    "context"
    "fmt"
    "os"

    "github.com/anthropics/anthropic-sdk-go/v2"
    "github.com/anthropics/anthropic-sdk-go/v2/option"
)

func main() {
    client := anthropic.NewClient(
        option.WithAPIKey(os.Getenv("DASHSCOPE_API_KEY")),
        option.WithBaseURL("https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic"),
    )
    response, err := client.Messages.New(context.Background(), anthropic.MessageNewParams{
        Model: "qwen4-max",
        MaxTokens: 1024,
        Messages: []anthropic.MessageParam{
            anthropic.NewUserMessage(anthropic.NewTextBlock("Who are you?")),
        },
    })
    if err != nil {
        panic(err)
    }
    for _, block := range response.Content {
        if block.Type == "text" {
            fmt.Println(block.Text)
        }
    }
}
using System;
using Anthropic;
using Anthropic.Models.Messages;

AnthropicClient client = new()
{
    ApiKey = Environment.GetEnvironmentVariable("DASHSCOPE_API_KEY"),
    BaseUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic"
};
MessageCreateParams parameters = new()
{
    Model = "qwen4-max",
    MaxTokens = 1024,
    Messages = [new UserMessageParam("Who are you?")]
};
var response = await client.Messages.Create(parameters);
foreach (var block in response.Content)
{
    if (block.TryPickText(out var text)) Console.WriteLine(text.Text);
}
require "anthropic"

client = Anthropic::Client.new(
  api_key: ENV.fetch("DASHSCOPE_API_KEY"),
  base_url: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic"
)
response = client.messages.create(
  model: "qwen4-max",
  max_tokens: 1024,
  messages: [{role: "user", content: "Who are you?"}]
)
response.content.each do |block|
  puts block.text if block.type == :text
end
<?php
require __DIR__ . "/vendor/autoload.php";

use Anthropic\Client;

$client = new Client(
    apiKey: getenv("DASHSCOPE_API_KEY"),
    baseUrl: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic"
);
$response = $client->messages->create(
    model: "qwen4-max",
    maxTokens: 1024,
    messages: [["role" => "user", "content" => "Who are you?"]]
);
foreach ($response->content as $block) {
    if ($block->type === "text") echo $block->text . PHP_EOL;
}

Commencez à créer

Inférence de modèles

Entraînement de modèles