Vercel 10 月 19 日在 AI Gateway 上架了 MiniMax M3.1 Flash,并写明免费到 10 月 22 日。模型名是 minimax/minimax-m3.1-flash,上下文 1M token。有一条容易漏:免费价只在 MiniMax 真正出站时生效,请求里要用 providerOptions.gateway.order 把 minimax 排到前面。

限免期限和调用方式

出处是 Vercel 的 changelog。原文写的是 now available on AI Gateway for free until Oct 22。模型页上输入输出价格当前显示为 Free,结构化数据里 input、output 也都是 0。

changelog 还写了 The free rate applies only when MiniMax serves the request。网关默认会按可用性和延迟挑提供方,想锁住免费价,要在网关选项里用 order 把 minimax 排第一。活动结束后,同样钉死的请求会按 MiniMax 刊例价计费。接口可以用 AI SDK、Chat Completions、Responses、Anthropic Messages,也能接到 Claude Code、Codex、Cursor 这类编码代理。

Chat Completions 的官方示例里,base URL 是 https://ai-gateway.vercel.sh/v1,密钥走环境变量 AI_GATEWAY_API_KEY。带上 provider 排序的 curl 大致是这样:

curl https://ai-gateway.vercel.sh/v1/chat/completions \
  -H "Authorization: Bearer $AI_GATEWAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "minimax/minimax-m3.1-flash",
    "messages": [{"role": "user", "content": "用一句话介绍 Spring Boot"}],
    "providerOptions": {
      "gateway": { "order": ["minimax"] }
    }
  }'

order 的写法见 AI Gateway 的 Provider Options 文档。接代理的话,官方给的命令是:

npx vercel ai-gateway setup

免费层和付费层的规则在 AI Gateway 计费文档。每个 Vercel team 都有免费层,免费层只能用部分模型,并且按模型限流,超了返回 429。买过 AI Gateway Credits 之后,账号转到付费层,每月免费额度不再适用。模型页当前显示这款模型的价格为 Free。

用 Spring AI 接网关

这里用 Spring Boot 4.1.1 和 Spring AI 2.0.1,JDK 21,依赖 OpenAI starter,改 base-url 指向 AI Gateway。

    <properties>
        <java.version>21</java.version>
        <spring-ai.version>2.0.1</spring-ai.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.ai</groupId>
                <artifactId>spring-ai-bom</artifactId>
                <version>${spring-ai.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-starter-model-openai</artifactId>
        </dependency>
    </dependencies>

配置文件:

spring:
  ai:
    openai:
      api-key: ${AI_GATEWAY_API_KEY}
      base-url: https://ai-gateway.vercel.sh/v1
      chat:
        model: minimax/minimax-m3.1-flash

控制器:

package com.example.demo;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ChatController {

    private final ChatClient chatClient;

    public ChatController(ChatClient.Builder builder) {
        this.chatClient = builder.build();
    }

    @GetMapping("/chat")
    public String chat(@RequestParam(defaultValue = "用一句话介绍 Spring Boot") String q) {
        return chatClient.prompt()
                .user(q)
                .call()
                .content();
    }
}

编译输出:

[INFO] --- compiler:3.15.0:compile (default-compile) @ vercel-minimax-demo ---
[INFO] Recompiling the module because of changed source code.
[INFO] Compiling 2 source files with javac [debug parameters release 21] to target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.435 s
[INFO] Finished at: 2026-10-21T08:11:53+08:00
[INFO] ------------------------------------------------------------------------

这个项目已编译但未实际调用 API,手上没有 AI Gateway 的 Key。Spring AI 的 OpenAI starter 默认不会带上 AI Gateway 的 providerOptions,真要钉死 MiniMax,还得在请求体里额外传 providerOptions.gateway.order,或者走官方 curl / AI SDK 示例。

空 Key 直接请求网关时返回的是:

curl -s -w '\nHTTP %{http_code}\n' https://ai-gateway.vercel.sh/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer ' \
  -d '{"model":"minimax/minimax-m3.1-flash","messages":[{"role":"user","content":"hi"}],"providerOptions":{"gateway":{"order":["minimax"]}}}'
{"error":{"message":"Authentication failed. Create an API key and set in AI_GATEWAY_API_KEY environment variable: https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai-gateway%2Fapi-keys%3FshowCreateKeyModal","type":"authentication_error"}}
HTTP 401

昨天写过 M3.1 Flash 在 OpenCode 里的免费档,那边直连接口会返回 403,只能在客户端里用,见 MiniMax M3.1 Flash 的 OpenCode 免费档只认客户端。Vercel 这条是另一条限免通道,截止日写在 changelog 上,是 10 月 22 日。

— 感谢阅读 —
广告

一起交流

分享你的思考,让讨论更进一步。