diff --git a/.github/actions/scan-nginx/action.yml b/.github/actions/scan-nginx/action.yml new file mode 100644 index 00000000..543b8ba7 --- /dev/null +++ b/.github/actions/scan-nginx/action.yml @@ -0,0 +1,31 @@ +name: Scan upstream Nginx +description: Check the running binary against upstream advisories and verify that Grype identified it. +inputs: + container: + description: Running container serving the site + required: true + grype-version: + description: Grype version used for the runtime image scan + required: true +runs: + using: composite + steps: + - name: Locate Grype + id: grype + uses: anchore/scan-action/download-grype@27805bf3b4e84b4a5c980df22ed233c00390a439 # v7.4.2 + with: + grype-version: ${{ inputs.grype-version }} + - name: Scan the running Nginx version + shell: bash + env: + CONTAINER: ${{ inputs.container }} + GRYPE: ${{ steps.grype.outputs.cmd }} + GRYPE_CHECK_FOR_APP_UPDATE: 'false' + run: | + scan_dir=$(mktemp -d "$RUNNER_TEMP/nginx-upstream.XXXXXXXX") + mkdir "$scan_dir/bin" + docker cp "$CONTAINER:/usr/sbin/nginx" "$scan_dir/bin/nginx" + version=$(docker exec "$CONTAINER" /usr/sbin/nginx -v 2>&1) + report="$scan_dir/report.cdx.json" + "$GRYPE" "dir:$scan_dir/bin" --fail-on negligible --only-fixed=false -o table -o "cyclonedx-json=$report" + node scripts/check-nginx-scan.mjs "$version" < "$report" diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0d3d75ca..6258ef7b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -25,6 +25,7 @@ on: env: IMAGE_NAME: bankofai/docs + GRYPE_VERSION: v0.121.3 jobs: lint: @@ -88,7 +89,7 @@ jobs: uses: anchore/scan-action@27805bf3b4e84b4a5c980df22ed233c00390a439 # v7.4.2 with: image: bankofai/docs:security-check - grype-version: v0.121.3 + grype-version: ${{ env.GRYPE_VERSION }} fail-build: true severity-cutoff: negligible only-fixed: false @@ -99,6 +100,12 @@ jobs: docker run --detach --name docs-security-smoke -p 127.0.0.1:8080:80 bankofai/docs:security-check node scripts/check-http-security.mjs http://127.0.0.1:8080 + - name: Scan the custom Nginx binary against upstream advisories + uses: ./.github/actions/scan-nginx + with: + container: docs-security-smoke + grype-version: ${{ env.GRYPE_VERSION }} + - name: Remove test container if: always() run: docker rm --force docs-security-smoke || true diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml index 4f69e776..fe34d530 100644 --- a/.github/workflows/release-publish.yml +++ b/.github/workflows/release-publish.yml @@ -7,6 +7,7 @@ on: env: IMAGE_NAME: bankofai/docs + GRYPE_VERSION: v0.121.3 jobs: checks: @@ -56,7 +57,7 @@ jobs: uses: anchore/scan-action@27805bf3b4e84b4a5c980df22ed233c00390a439 # v7.4.2 with: image: bankofai/docs:security-check - grype-version: v0.121.3 + grype-version: ${{ env.GRYPE_VERSION }} fail-build: true severity-cutoff: negligible only-fixed: false @@ -67,6 +68,12 @@ jobs: docker run --detach --name docs-security-smoke -p 127.0.0.1:8080:80 bankofai/docs:security-check node scripts/check-http-security.mjs http://127.0.0.1:8080 + - name: Scan the custom Nginx binary against upstream advisories + uses: ./.github/actions/scan-nginx + with: + container: docs-security-smoke + grype-version: ${{ env.GRYPE_VERSION }} + - name: Remove test container if: always() run: docker rm --force docs-security-smoke || true diff --git a/.github/workflows/site-checks.yml b/.github/workflows/site-checks.yml index f01ee673..e53f052a 100644 --- a/.github/workflows/site-checks.yml +++ b/.github/workflows/site-checks.yml @@ -25,7 +25,7 @@ jobs: run: yarn install --frozen-lockfile --non-interactive - name: Audit all dependency severities - run: yarn audit --non-interactive --network-timeout 60000 + run: node scripts/audit-dependencies.mjs - name: Lint run: yarn lint diff --git a/Dockerfile b/Dockerfile index ad7e347f..266e5523 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,7 @@ WORKDIR /app # Copy package.json and yarn.lock COPY package*.json yarn.lock ./ +COPY scripts/patch-picomatch.mjs ./scripts/ RUN echo "Build environment is ${APP_ENV}" @@ -28,13 +29,26 @@ COPY . . # Build the Docusaurus app RUN yarn build -# Stage 2: Assemble the Nginx runtime without BusyBox (CVE-2025-60876). -# Package installation and inspection tools stay in this intermediate stage. -FROM nginx:1.31-alpine3.24 AS runtime-files - -RUN apk upgrade --no-cache \ - && apk add --no-cache 'brotli-libs>=1.2.1-r0' scanelf - +# Build a signed HTTP-only package. abuild records the compiled ELF dependencies. +FROM alpine:3.24 AS nginx-build +RUN apk add --no-cache abuild build-base pcre2-dev zlib-dev \ + && adduser -D -G abuild builder +WORKDIR /home/builder/docs/nginx +COPY docker/nginx/APKBUILD . +RUN chown builder:abuild . \ + && su builder -c 'abuild-keygen -an' \ + && cp /home/builder/.abuild/*.rsa.pub /etc/apk/keys/ \ + && su builder -c 'abuild' \ + && mkdir /out \ + && cp /home/builder/packages/docs/*/nginx-*.apk /home/builder/.abuild/*.rsa.pub /out/ \ + && rm /home/builder/.abuild/*.rsa + +# Resolve current Alpine libraries for the actual binary on every CI build. +FROM alpine:3.24 AS runtime-files +RUN addgroup -S -g 101 nginx \ + && adduser -S -D -H -u 101 -G nginx -s /sbin/nologin nginx + +COPY --from=nginx-build /out/ /tmp/nginx-package/ COPY scripts/prepare-nginx-runtime.sh /usr/local/bin/prepare-nginx-runtime RUN sh /usr/local/bin/prepare-nginx-runtime @@ -43,8 +57,7 @@ COPY default.conf /runtime/etc/nginx/conf.d/default.conf COPY --from=build /app/.site-security/nginx-headers.conf /runtime/etc/nginx/snippets/security-headers.conf COPY --from=build /app/build /runtime/usr/share/nginx/html -# Stage 3: Only the server, its shared libraries, package inventory and site ship. -# The upstream shell entrypoint is unnecessary: all configuration is copied above. +# Only the server, its shared libraries, package inventory and site ship. FROM scratch AS runtime COPY --from=runtime-files /runtime/ / diff --git a/README.md b/README.md index 26876aea..a836e851 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ The site explicitly loads the official docs, pages, debug and sitemap plugins an ### Production security checks -The container assembles a minimal runtime from the official Alpine Nginx binary and its ELF library dependencies. BusyBox, its `wget`/`ssl_client` tooling, shells, package managers and unused dynamic Nginx modules stay outside the final image. The runtime keeps the original Nginx APK inventory and the installed libraries' package records so Grype still scans the software that ships. CI refreshes the `runtime-files` stage on every build; its Alpine packages are not reused from a cached security-update layer. +The container serves HTTP behind the TLS-terminating reverse proxy. Alpine's `abuild` verifies the pinned Nginx source archive, builds it without OpenSSL, and records the binary's ELF dependencies in a signed APK. CI refreshes the runtime libraries on every build and rejects OpenSSL shared libraries, BusyBox and shell tooling in the runtime. Grype scans the installed Alpine packages and checks the extracted Nginx binary against upstream advisories. Publishing requires the upstream scan to identify the version reported by the running server. To upgrade Nginx, verify the new upstream release signature and update the version and SHA-512 in `docker/nginx/APKBUILD`. The container still listens on port 80 and writes logs to `/app/logs`. Its entrypoint directly runs `/usr/sbin/nginx`, preserves graceful `SIGQUIT` shutdown, and validates configuration with an exec-form `nginx -t` during the build. There is no `docker exec ... sh`; inspect logs externally or run `docker run --rm IMAGE -t` to check configuration. diff --git a/docker/nginx/APKBUILD b/docker/nginx/APKBUILD new file mode 100644 index 00000000..9f577134 --- /dev/null +++ b/docker/nginx/APKBUILD @@ -0,0 +1,39 @@ +pkgname=nginx +pkgver=1.31.8 +pkgrel=0 +pkgdesc="NGINX HTTP server for BofAI docs" +url="https://nginx.org/" +arch="all" +license="BSD-2-Clause" +makedepends="pcre2-dev zlib-dev" +source="https://nginx.org/download/nginx-$pkgver.tar.gz" + +build() { + # TLS terminates at the ingress. The default HTTP build includes gzip, + # PCRE and the modules used by nginx.conf, without linking OpenSSL. + ./configure \ + --prefix=/var/cache/nginx \ + --conf-path=/etc/nginx/nginx.conf \ + --pid-path=/run/nginx.pid \ + --lock-path=/run/nginx.lock \ + --error-log-path=/var/log/nginx/error.log \ + --http-log-path=/var/log/nginx/access.log \ + --user=nginx --group=nginx \ + --with-cc-opt="$CFLAGS $CPPFLAGS" \ + --with-ld-opt="$LDFLAGS -Wl,-z,relro,-z,now" + make +} + +check() { + test "$(objs/nginx -v 2>&1)" = "nginx version: nginx/$pkgver" +} + +package() { + install -Dm755 objs/nginx "$pkgdir/usr/sbin/nginx" + install -Dm644 conf/mime.types "$pkgdir/etc/nginx/mime.types" + install -Dm644 LICENSE "$pkgdir/usr/share/licenses/nginx/LICENSE" +} + +sha512sums=" +b05679bd30746f41b17343be570ed62b2bb0bc64e15d24d8af307db03d5227ab6b1da57bb4b640ad4d4c854a0c0233285d5ba294caa4ad199c49522883700fce nginx-1.31.8.tar.gz +" diff --git a/docs/llmservice/api/API.md b/docs/llmservice/api/API.md index da177525..992d4ea8 100644 --- a/docs/llmservice/api/API.md +++ b/docs/llmservice/api/API.md @@ -2,13 +2,13 @@ B.AI provides a unified large language model API compatible with the OpenAI Chat Completions, OpenAI Responses, and Anthropic Messages protocols, as well as a Decisions API compatible with the TypeSafe System One protocol. Use the same B.AI API Key with different protocols and choose the endpoint that matches your application or client. -B.AI also provides an asynchronous [Video Generation API](./videos.md) to create tasks, query their status, and download completed videos. +B.AI also provides the [MiniMax Image Generation API](./minimax-image-generation.md) for synchronous text-to-image generation and reference-image editing, with optional SSE streaming. The asynchronous [Video Generation API](./videos.md) supports creating tasks, querying their status, and downloading completed videos. The [Recharge API](./recharges.md) uses a separate service origin, `https://chat.b.ai`, for cryptocurrency recharge orders. To use it through an Agent, see the [Recharge Skill Guide](./recharge-skill-guide.md). - **API version:** `v1` - **Production Base URL:** `https://api.b.ai/v1` -- **Request format:** `application/json` +- **Request format:** `application/json` by default; image editing also supports `multipart/form-data`, which is required for reference-image uploads. - **Character encoding:** UTF-8 - **Text-generation streaming:** Server-Sent Events (SSE) @@ -52,7 +52,7 @@ Replace `your-model-id` with a model ID enabled for the selected endpoint. B.AI supports the following authentication headers. Both use the same platform-issued API Key; choose either one. -For video generation, use the Bearer authentication shown in the [Video Generation API](./videos.md) request example; `x-api-key` support for that endpoint is not documented here. +For image generation, editing, reference-image uploads, and video generation, use the Bearer authentication shown in the [MiniMax Image Generation API](./minimax-image-generation.md) and [Video Generation API](./videos.md) examples. This reference does not establish `x-api-key` support for those endpoints. Recharge endpoints also require Bearer authentication. Do not assume that the model service's `x-api-key` alternative applies to recharge requests. @@ -94,6 +94,9 @@ Example: | `POST` | `/responses` | OpenAI Responses | Agents, reasoning, tool use, and Codex | | `POST` | `/chat/completions` | OpenAI Chat Completions | General chat completions and existing OpenAI-compatible applications | | `POST` | `/messages` | Anthropic Messages | Claude SDK, Claude Code, and other Anthropic-compatible clients | +| `POST` | [`/images/generations`](./minimax-image-generation.md) | OpenAI SDK-compatible; see model-specific parameters | Generate MiniMax images synchronously, with optional SSE streaming | +| `POST` | [`/images/edits`](./minimax-image-generation.md) | OpenAI SDK-compatible; see model-specific parameters | Edit MiniMax images using references; accepts JSON or multipart form data | +| `POST` | [`/files/upload`](./minimax-image-generation.md#upload-reference-images) | - | Upload reference images with `purpose=image_generation_input` for `mm_file://` references | | `POST` | [`/videos`](./videos.md) | - | Create an asynchronous video-generation task | | `GET` | [`/videos/{task_id}`](./videos.md) | - | Query a video task's generation and billing status | | `GET` | [`/videos/{task_id}/content`](./videos.md) | - | Download a completed and settled video with authentication | diff --git a/docs/llmservice/api/minimax-image-generation.md b/docs/llmservice/api/minimax-image-generation.md new file mode 100644 index 00000000..3b3375d2 --- /dev/null +++ b/docs/llmservice/api/minimax-image-generation.md @@ -0,0 +1,394 @@ +# MiniMax Image Generation API + +B.AI's image API supports text-to-image generation and reference-image editing, returning results synchronously: + +**Send a request -> Read the response -> Download the images.** + +With `stream` enabled, images are sent individually as they finish, without waiting for the entire batch. + +This reference covers **MiniMax-H3-Image** and **MiniMax-H3-Image-Highspeed**. For capabilities and standard prices, see the [shared model detail page](../image-models/minimax-h3-image.md). + +## Preparation + +### API Host + +```text +https://api.b.ai +``` + +### Authentication + +All endpoints require a B.AI API Key: + +```http +Authorization: Bearer YOUR_API_KEY +``` + +Personal and Team API Keys are supported. The examples use this environment variable: + +```bash +export BAI_API_KEY="YOUR_API_KEY" +``` + +Image generation incurs charges. Ensure your account has sufficient balance. + +### Model IDs + +| Model | Request `model` | +| --- | --- | +| MiniMax-H3-Image | `minimax-h3-image` | +| MiniMax-H3-Image-Highspeed | `minimax-h3-image-highspeed` | + +The Highspeed variant uses the same parameters and limits. Change only the `model` field to switch variants. + +Available models depend on your account's access. Use `GET https://api.b.ai/v1/models` to list model IDs associated with your current API credential. + +## 1. Generate Images from Text + +```http +POST https://api.b.ai/v1/images/generations +``` + +Submit a JSON request. The server generates the images synchronously and returns the results. **The server may wait up to 600 seconds; set the client timeout to at least 600 seconds.** + +### Request Example + +```bash +curl https://api.b.ai/v1/images/generations \ + -H "Authorization: Bearer ${BAI_API_KEY}" \ + -H "Content-Type: application/json" \ + -d '{ + "model": "minimax-h3-image", + "prompt": "An orange cat resting on a windowsill in warm afternoon sunlight, with a film-like texture.", + "size": "2720x1536", + "n": 1, + "response_format": "url" + }' +``` + +### Main Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| `model` | string | Required model ID. | +| `prompt` | string | Required image description, up to 32,000 characters. Empty or whitespace-only prompts return `400`. | +| `n` | integer | Number of images, from 1 to 10. Defaults to `1`. | +| `size` | string | Output dimensions; defaults to `auto`. Explicit dimensions cannot be combined with `aspect_ratio` or `area`; see Output Size below. | +| `aspect_ratio` | string | Defaults to `auto`. In `X:Y`, X and Y must be integers from 1 to 300, and the ratio must be between 1:3 and 3:1, inclusive. | +| `area` | string | Area preset: `1K`, `2K`, or `4K`. Defaults to `4K`. Only allowed when `size` is `auto` or omitted. | +| `output_format` | string | `jpeg` (default), `jpg`, `png`, or `webp`. `jpg` is equivalent to `jpeg`; the response uses `jpeg`. | +| `response_format` | string | `url` (default) or `b64_json`. `b64_json` does not support streaming. | +| `output_compression` | integer | Compression quality from 0 to 100; defaults to `95`. Applies to `jpeg` and `webp`; ignored for `png`. | +| `disable_prompt_enhanced` | boolean | Whether to disable prompt enhancement. Defaults to `false`, so enhancement is enabled. | +| `stream` | boolean | Whether to stream results. Defaults to `false`. | + +### Output Size + +Choose one of the following modes. When `size` is `WIDTHxHEIGHT`, also providing `aspect_ratio` or `area`, even as `auto`, returns `400`. + +**Explicit dimensions:** + +```json +{ "size": "2720x1536" } +``` + +The total area (width times height) must be between 655,360 and 20,000,000 pixels, and the aspect ratio must be between 1:3 and 3:1, inclusive. Invalid values return `400`. **Explicit dimensions are not resized or rounded.** + +**Aspect ratio and area preset:** + +```json +{ "aspect_ratio": "16:9", "area": "2K" } +``` + +The target areas are 1024 x 1024, 2048 x 2048, and 4096 x 4096 pixels. The server converts the selected ratio and area into dimensions: + +| Aspect Ratio | `1K` | `2K` | `4K` | +| --- | --- | --- | --- | +| 1:1 | `1024x1024` | `2048x2048` | `4096x4096` | +| 4:3 / 3:4 | `1184x880` / `880x1184` | `2368x1760` / `1760x2368` | `4736x3552` / `3552x4736` | +| 16:9 / 9:16 | `1360x768` / `768x1360` | `2720x1536` / `1536x2720` | `5472x3072` / `3072x5472` | +| 3:1 / 1:3 | `1776x592` / `592x1776` | `3552x1184` / `1184x3552` | `7104x2368` / `2368x7104` | + +The actual dimensions of each image are returned in `data[].size`. + +### Prompt Enhancement + +Text-to-image generation enables prompt enhancement by default. The server rewrites and expands the prompt, returning the version used in `data[].revised_prompt`. + +- With `disable_prompt_enhanced: true`, the original prompt is used. You must specify explicit dimensions (`size: "WIDTHxHEIGHT"`), or a fixed `aspect_ratio: "X:Y"` with `size` set to `auto` or omitted. Otherwise the request returns `400`. +- With enhancement disabled, only approximately the first 4,096 tokens of the prompt take effect. +- To reuse or refine an enhanced prompt, use `revised_prompt` as the next request's `prompt`, edit it as needed, and set `disable_prompt_enhanced: true`. This does not guarantee an identical image. + +### Generation Response + +A successful response returns HTTP `200`. `data` contains `n` elements in request order. The following example shows **partial success for a request with `n=2`**: + +```json +{ + "created": 1792308678, + "data": [ + { + "url": "https://example.com/h3-image/output-0.jpg", + "size": "2720x1536", + "revised_prompt": "Warm afternoon sunlight falls through a wooden window onto an orange cat resting on the sill, with softly lit fur, blurred indoor plants, and subtle film grain." + }, + { + "error": { + "code": "1027", + "message": "output image failed content safety check" + } + } + ], + "output_format": "jpeg", + "usage": { + "generated_images": 1, + "total_tokens": 7254, + "input_tokens": 3174, + "output_tokens": 4080, + "input_tokens_details": { + "text_tokens": 3174, + "image_tokens": 0 + }, + "output_tokens_details": { + "image_tokens": 4080 + } + }, + "request_id": "021792308678142a2c883cf675b9804d" +} +``` + +The response body's `request_id` identifies the upstream generation. **When reporting a problem, provide the response header `X-Oneapi-Request-Id`**, which B.AI uses for request records and logs. Every response includes this header. + +### Partial Failures + +If at least one image succeeds, the endpoint returns `200`. Failed images, including those blocked by content safety checks, contain only `error`, not `url`. `usage.generated_images` reports the number of successful images. **Only successfully generated images are billed.** + +If every image fails, the error response includes per-image failure reasons and `usage`: + +- `422`: All images failed content safety checks. +- `500`: Other failures. + +### Duplicate Requests and Retries + +This endpoint is **not idempotent**. Once a request is sent, B.AI completes generation and bills successfully generated images even if the client times out or disconnects. Retrying creates another generation and may incur another charge. + +Do not immediately resend a request after a network timeout or temporary error: + +- When using the OpenAI SDK, set `max_retries=0` to disable automatic retries. +- Record the response header `X-Oneapi-Request-Id` and your application's task identifier. Check whether the earlier request incurred charges before deciding to resend it. + +## 2. Edit Images Using References + +```http +POST https://api.b.ai/v1/images/edits +``` + +Provide 1-16 reference images alongside a prompt to edit subjects, scenes, or styles. Apart from prompt enhancement behavior, parameters are the same as text-to-image generation. + +### Request Example + +```bash +curl https://api.b.ai/v1/images/edits \ + -H "Authorization: Bearer ${BAI_API_KEY}" \ + -H "Content-Type: application/json" \ + -d '{ + "model": "minimax-h3-image", + "prompt": "Replace the cat in image 1 with the Shiba Inu from image 2, keeping the background unchanged.", + "images": [ + { "image_url": "https://example.com/cat.jpg" }, + { "image_url": "https://example.com/dog.png" } + ], + "size": "auto", + "response_format": "url" + }' +``` + +The endpoint also accepts `multipart/form-data`, compatible with the OpenAI SDK's `images.edit`. File upload order determines the image numbers, which can be referenced in the prompt as "image 1", "image 2", and so on. + +### Reference Image Limits + +| Item | Limit | +| --- | --- | +| Formats | JPG, JPEG, PNG, WEBP, HEIC, HEIF | +| File size | Up to 64 MiB per image | +| Total request body | Up to 64 MiB | +| Width and height | 128-8192 pixels per side | +| Long-side to short-side ratio | Up to 4:1 | +| Number of images | 1-16 | + +`images[].image_url` accepts: + +- A publicly accessible URL (recommended). +- `mm_file://{file_id}`, referencing an uploaded file. +- A data URI: `data:image/;base64,`, with a lowercase ``. + +Base64 encoding increases file size to approximately 4/3 of the original. **If the request body may exceed 64 MiB, use public URLs or `mm_file://` references instead.** + +### Upload Reference Images + +Before using `mm_file://`, upload the reference image with `purpose` set to `image_generation_input`. Use the returned `file_id` to construct `mm_file://{file_id}`. + +```bash +curl https://api.b.ai/v1/files/upload \ + -H "Authorization: Bearer ${BAI_API_KEY}" \ + -F "purpose=image_generation_input" \ + -F "file=@cat.jpg" +``` + +### Differences from Text-to-Image Generation + +- `images` is required. +- **Prompt enhancement is always enabled.** `disable_prompt_enhanced` is unsupported. +- With `aspect_ratio: "auto"`, prompt enhancement determines the ratio using the reference images and prompt. +- Prompt enhancement input tokens are included in `usage.input_tokens_details.text_tokens`. + +## 3. Streaming Results + +Set `stream: true` in a generation or edit request. The server sends individual results using SSE (`text/event-stream`). **Only `response_format: "url"` is supported.** + +### Request Example + +```bash +curl -N https://api.b.ai/v1/images/generations \ + -H "Authorization: Bearer ${BAI_API_KEY}" \ + -H "Content-Type: application/json" \ + -d '{ + "model": "minimax-h3-image", + "prompt": "An orange cat resting on a windowsill in warm afternoon sunlight, with a film-like texture.", + "size": "2720x1536", + "n": 3, + "stream": true + }' +``` + +### Event Types + +| Event | Description | +| --- | --- | +| `.partial_succeeded` | One image succeeded; includes `image_index`, `url`, `size`, `output_format`, and `revised_prompt`. | +| `.partial_failed` | One image failed; includes `image_index`, `code`, and `message`. | +| `.completed` | Processing finished with at least one successful image; includes `usage` and `request_id`. | +| `error` | No images succeeded, including failures before generation starts. No charges apply and all `usage` fields are zero. | + +`` is `image_generation` for text-to-image generation and `image_edit` for editing. + +Events arrive in completion order. Use `image_index`, starting at 0 and ranging from `[0, n-1]`, to identify the image. During processing, the server sends a `: keepalive` comment every 15 seconds; clients can ignore it. + +**Check the HTTP status before parsing SSE.** Errors that occur before response headers are sent, such as invalid parameters, authentication failure, rate limiting, or insufficient balance, return regular HTTP error responses rather than an SSE `error` event. + +## 4. Download Images + +Download and store images returned in `url` yourself. **The platform does not guarantee that these URLs remain available long-term.** Save generated images promptly. + +```bash +curl --fail --location \ + "https://example.com/h3-image/output-0.jpg" \ + --output output-0.jpg +``` + +With `response_format: "b64_json"`, the image data is returned directly in `data[].b64_json`, so no separate download is required. This mode does not support streaming and has total output-area limits: + +| `output_format` | Maximum Total Area for `b64_json` | Example | +| --- | --- | --- | +| `png` | 20,000,000 pixels | One image of any supported size | +| `jpeg` / `webp` | 80,000,000 pixels | Four 4K images or ten 2K images | + +Requests above these limits return `400`. Use `url` instead. + +## OpenAI SDK Compatibility + +Both image endpoints are compatible with the OpenAI SDK. Set `base_url` to B.AI: + +```python +import os +from openai import OpenAI + +client = OpenAI( + base_url="https://api.b.ai/v1", + api_key=os.environ["BAI_API_KEY"], + timeout=600, + max_retries=0, # Avoid duplicate generation and charges on this non-idempotent API. +) + +result = client.images.generate( + model="minimax-h3-image", + prompt="An orange cat resting on a windowsill in warm afternoon sunlight, with a film-like texture.", + size="2720x1536", + response_format="url", +) + +for i, item in enumerate(result.data): + print(i, item.url) # Failed images have no URL. +``` + +## Usage and Rate Limits + +### Usage + +- The response's `usage` object counts **only successfully generated images**, excluding failed images and those blocked by safety checks. +- `input_tokens` includes text-prompt and reference-image input tokens. `output_tokens` counts generated-image output tokens; `total_tokens` is their sum. +- Prompt enhancement input tokens count toward `usage.input_tokens`, once per image (`n` images means `n` enhancement runs). Billing usage includes only successful images; refer to the response's actual `usage`. +- For both variants' token rates, see [Image Generation Model Pricing](../image-models/pricing.md). + +### Rate Limits + +Image endpoints are rate-limited **per account, by request count**: + +| Item | Limit | +| --- | --- | +| Requests per minute per account | 16 | + +Both MiniMax variants and GPT-Image-2 **share this quota**. + +Request count does not depend on `n`: `n=10` still counts as one request. Exceeding the limit returns `429` with `code: persistent_image_rate_limited`. Reduce the request frequency before retrying. + +## Common Errors + +Errors have two levels: platform-level errors use HTTP status codes, while individual image failures appear in `data[].error`. + +### Platform-Level Errors + +| HTTP Status | Common Cause | +| --- | --- | +| `400` | Invalid parameters, parameters not listed in this reference, or insufficient balance | +| `401` | Invalid or expired API Key | +| `403` | Access restrictions or Team member quota limits | +| `404` | Endpoint or model does not exist, or the current identity lacks access | +| `429` | Request rate limit exceeded | +| `500` | Server error | +| `502` / `503` | Temporary service error | + +Two common `400` errors: + +| Error Identifier / Message | Meaning | Action | +| --- | --- | --- | +| `unknown image parameter` (message) | A parameter not listed here was sent, such as `seed` | Remove the parameter | +| `code: insufficient_user_quota` | Insufficient account balance | Recharge before retrying | + +Error responses use this structure: + +```json +{ + "error": { + "code": "", + "message": "Invalid token (request id: 2026111307415255722563c955d568zj7buxCT)", + "type": "api_error" + } +} +``` + +**When reporting a problem, provide the response header `X-Oneapi-Request-Id`**, which identifies B.AI's request records and logs. Some errors, including `429`, do not include a request ID in `message`. + +### Individual Image Errors + +`data[].error.code` identifies an individual image failure: + +| Code | Meaning | Action | +| --- | --- | --- | +| `1000` | Unknown error / server error | Retry later | +| `1001` | Request timed out | Retry later | +| `1026` | Input blocked by content safety checks | Revise the input | +| `1027` | Output blocked by content safety checks | Revise the input | +| `2013` | Invalid parameters | Check the request parameters | + +**Retry carefully:** Image requests are not idempotent. Resending creates a new generation and may incur new charges. After a timeout or network error, check whether the earlier request incurred charges before resending. Only retry 5xx responses and explicit rate-limit errors; retrying invalid parameters (`400`), authentication errors (`401`), insufficient balance (`400`), or safety rejections (`422`) without addressing their cause does not help. diff --git a/docs/llmservice/image-models/minimax-h3-image.md b/docs/llmservice/image-models/minimax-h3-image.md index 3e3d611d..ecd76a86 100644 --- a/docs/llmservice/image-models/minimax-h3-image.md +++ b/docs/llmservice/image-models/minimax-h3-image.md @@ -4,6 +4,8 @@ [MiniMax-H3-Image](https://www.minimax.io/blog/minimax-h3-image) is MiniMax's open-weight H3-family model for image generation and editing, released on November 11, 2026. It combines detailed instruction following, multi-reference composition, and native 4K generation for creative and product design workflows. +For generation and editing requests, reference-image uploads, streaming events, and error handling, see the [MiniMax Image Generation API](../api/minimax-image-generation.md). + ## Model Variants | Model | Description | diff --git a/docs/llmservice/models/deepseek-v4-1-flash.md b/docs/llmservice/models/deepseek-v4-1-flash.md index ce0678fe..fa5691b8 100644 --- a/docs/llmservice/models/deepseek-v4-1-flash.md +++ b/docs/llmservice/models/deepseek-v4-1-flash.md @@ -14,11 +14,17 @@ B.AI will progressively route requests made using the `DeepSeek-V4-Flash` and `D variant="discount" title="DeepSeek-V4.1-Flash" status="Limited-Time Discount" - detail="60% from Oct 4, 10:00 SGT" + detail="50% OFF" > -The offer takes effect at 10:00 on October 4, 2026 (SGT, UTC+8). -From that time, the promotional price changes in step with DeepSeek's time-based pricing and is billed at 60% of the applicable Off-Peak or Peak standard price. +During the promotion, input, output, cache writes, and cache reads are billed at 50% of the applicable Off-Peak or Peak standard reference price. Promotional prices change in step with DeepSeek's time-based pricing. + +The promotional prices below are in USD per 1 million tokens. + +| Billing Period | Input | Cache Write | Cache Read | Output | +| :--- | ---: | ---: | ---: | ---: | +| Off-Peak | `$0.075` | `$0.075` | `$0.0015` | `$0.30` | +| Peak | `$0.15` | `$0.15` | `$0.003` | `$0.60` | The pricing table below continues to show standard reference prices. Actual settlement and final billing are subject to the platform display. diff --git a/docs/llmservice/models/gpt-6-2-astra.md b/docs/llmservice/models/gpt-6-2-astra.md new file mode 100644 index 00000000..0a4abb6d --- /dev/null +++ b/docs/llmservice/models/gpt-6-2-astra.md @@ -0,0 +1,62 @@ +# GPT-6.2 Astra + +## Overview + +GPT-6.2 Astra is OpenAI's GPT-6.2 reasoning model for demanding software engineering and professional projects, [released on November 17, 2026](https://developers.openai.com/api/docs/changelog). It combines text and image understanding, adjustable reasoning, and tool use to plan and complete complex work. + +## Key Features + +- **Complex Project Work**: Plans and carries out projects, adapting its approach as new information becomes available. +- **Software Engineering**: Builds and revises software, using code execution and editing tools to support implementation and verification. +- **Visual Computer Use**: Interprets screenshots and works with computer-use tools to carry out tasks across applications. +- **Long Working Context**: Accommodates extensive source material, code, and conversation history within a 1.05M-token context window. +- **Agent Delegation**: Supports the Responses API Multi-agent beta, allowing independent subtasks to be delegated to subagents. +- **Clear Writing**: Produces concise, direct writing by default, with tone and detail adjustable for the intended audience. + +## Best Use Cases + +- **Complex Software Projects**: Implementation, debugging, and code review that involve multiple components and repeated testing. +- **Research and Technical Decisions**: Open-ended analysis that requires comparing evidence, testing assumptions, and weighing trade-offs. +- **Professional Deliverables**: Turning a detailed brief and supporting material into reports, documents, or applications with iterative revision. +- **Computer-Based Workflows**: Coordinating a sequence of actions across interfaces, files, and connected tools. + +## Capabilities and Limitations + +| Capability | Description | +| :--- | :--- | +| **Reasoning** | Supports `low`, `medium`, `high`, `xhigh`, and `max`; `none` and `minimal` are unsupported. | +| **Multimodal** | Text and image input; text output. Native audio and video are unsupported. | +| **Context Window** | [1,050,000 tokens](https://developers.openai.com/api/docs/models/gpt-6.2-astra), shared by input and generated tokens. | +| **Max Input** | 922,000 tokens. | +| **Max Output** | 128,000 tokens, including reasoning and visible output. | +| **Tool Use** | Supports functions, web and file search, code execution, computer use, MCP, and image generation through Responses API tools. | +| **Structured Output** | Supports Structured Outputs and streaming. | +| **Prompt Caching** | Supports implicit and explicit caching, with 30-minute or 12-hour minimum lifetimes in the Responses API. | +| **Knowledge Cutoff** | May 18, 2026. | + +### Known Limitations + +- Tool calling requires the Responses API; Chat Completions supports requests without tools. +- Sampling and log-probability controls are unsupported. Fine-tuning is unavailable. +- Reasoning consumes the output budget and can increase latency; an insufficient budget can leave a response incomplete before a visible answer is produced. +- Editing earlier conversation content or switching to a smaller model can discard prior reasoning, reducing continuity and increasing repeated work. + +## Standard Pricing + +The token prices below are shown in USD per 1 million tokens; web search is billed in USD per use. + +| Context | Input
(USD / 1M Tokens) | 30m Cache Write
(USD / 1M Tokens) | 12h Cache Write
(USD / 1M Tokens) | Cache Read
(USD / 1M Tokens) | Output
(USD / 1M Tokens) | Web Search
(USD / use) | +| :--- | ---: | ---: | ---: | ---: | ---: | ---: | +| Up to 272K input tokens | `$8.00` | `$10.00` | `$20.00` | `$0.40` | `$40.00` | `$0.01` | +| More than 272K input tokens | `$16.00` | `$20.00` | `$40.00` | `$0.80` | `$60.00` | `$0.01` | + +- Above 272K input tokens, the higher rates apply to the entire request, not only the portion above the threshold. +- [Cache-write charges](https://developers.openai.com/api/docs/guides/prompt-caching) apply to both implicit and explicit caching and replace the ordinary input charge for those tokens. The default minimum lifetime is 30 minutes. A 30-minute write costs 1.25x the applicable input rate; a 12-hour write costs 2.5x. Both lifetimes have the same cache-read rate, 0.05x the applicable input rate. +- Reasoning tokens are billed as output tokens. +- Web search costs `10,000 Credits` (`$0.01`) per use and is not affected by the context tier. Search content tokens are billed at the applicable model token rates. + +**Credits settlement:** B.AI converts charges at `1 USD = 1,000,000 Credits` and deducts Credits from the account balance. + +:::info Pricing note +Model prices in the documentation are based on the model providers' official list prices and serve as B.AI standard reference prices. B.AI may offer discounts or limited-time promotions on this basis; offer details are shown in [Promotions and Pricing Updates](../promotions-and-pricing-notices.md) and the website's discount groups. Applicable prices, offer terms, and final charges are subject to the platform display and actual billing records. +::: diff --git a/docs/llmservice/models/gpt-6-2-sol.md b/docs/llmservice/models/gpt-6-2-sol.md new file mode 100644 index 00000000..c9abe712 --- /dev/null +++ b/docs/llmservice/models/gpt-6-2-sol.md @@ -0,0 +1,62 @@ +# GPT-6.2 Sol + +## Overview + +GPT-6.2 Sol is OpenAI's GPT-6.2 reasoning model for everyday coding, professional work, and agent workflows, [released on November 17, 2026](https://developers.openai.com/api/docs/changelog). It combines text and image understanding with tool use and long context, offering a lower-cost option than Astra for complex work. + +## Key Features + +- **Everyday Software Development**: Supports bug fixes, feature additions, and other work in existing codebases. +- **Iterative Task Execution**: Works through multistep tasks that require testing and revision along the way. +- **Tool-Based Agents**: Supports search, code execution, computer use, and connected tools through the Responses API. +- **Adjustable Reasoning**: Lets applications balance reasoning depth, response time, and token usage; OpenAI recommends starting with medium effort for a new integration. +- **Long Working Context**: Combines a 1.05M-token context window with prompt caching for reusable instructions and reference material. +- **Agent Delegation**: Supports the Responses API Multi-agent beta for delegating independent subtasks to subagents. + +## Best Use Cases + +- **Codebase Maintenance**: Fixing bugs, adding scoped features, and revising code with clear acceptance criteria. +- **Operational Assistants**: Completing repeatable workflows that combine information retrieval, application interaction, and tool calls. +- **Document Drafting**: Turning notes and source material into drafts for review, then incorporating feedback. +- **Document and Image Analysis**: Reviewing lengthy reference material alongside screenshots or other images, and returning structured findings. + +## Capabilities and Limitations + +| Capability | Description | +| :--- | :--- | +| **Reasoning** | Supports `low`, `medium`, `high`, `xhigh`, and `max`; `none` and `minimal` are unsupported. | +| **Multimodal** | Text and image input; text output. Native audio and video are unsupported. | +| **Context Window** | [1,050,000 tokens](https://developers.openai.com/api/docs/models/gpt-6.2-sol), shared by input and generated tokens. | +| **Max Input** | 922,000 tokens. | +| **Max Output** | 128,000 tokens, including reasoning and visible output. | +| **Tool Use** | Supports functions, web and file search, code execution, computer use, MCP, and image generation through Responses API tools. | +| **Structured Output** | Supports Structured Outputs and streaming. | +| **Prompt Caching** | Supports implicit and explicit caching, with 30-minute or 12-hour minimum lifetimes in the Responses API. | +| **Knowledge Cutoff** | June 1, 2026. | + +### Known Limitations + +- Tool calling requires the Responses API; Chat Completions supports requests without tools. +- Sampling and log-probability controls are unsupported. Fine-tuning is unavailable. +- Reasoning consumes the output budget and can increase latency; an insufficient budget can leave a response incomplete before a visible answer is produced. +- Editing earlier conversation content or switching to a smaller model can discard prior reasoning, reducing continuity and increasing repeated work. + +## Standard Pricing + +The token prices below are shown in USD per 1 million tokens; web search is billed in USD per use. + +| Context | Input
(USD / 1M Tokens) | 30m Cache Write
(USD / 1M Tokens) | 12h Cache Write
(USD / 1M Tokens) | Cache Read
(USD / 1M Tokens) | Output
(USD / 1M Tokens) | Web Search
(USD / use) | +| :--- | ---: | ---: | ---: | ---: | ---: | ---: | +| Up to 272K input tokens | `$2.00` | `$2.50` | `$5.00` | `$0.10` | `$10.00` | `$0.01` | +| More than 272K input tokens | `$4.00` | `$5.00` | `$10.00` | `$0.20` | `$15.00` | `$0.01` | + +- Above 272K input tokens, the higher rates apply to the entire request, not only the portion above the threshold. +- [Cache-write charges](https://developers.openai.com/api/docs/guides/prompt-caching) apply to both implicit and explicit caching and replace the ordinary input charge for those tokens. The default minimum lifetime is 30 minutes. A 30-minute write costs 1.25x the applicable input rate; a 12-hour write costs 2.5x. Both lifetimes have the same cache-read rate, 0.05x the applicable input rate. +- Reasoning tokens are billed as output tokens. +- Web search costs `10,000 Credits` (`$0.01`) per use and is not affected by the context tier. Search content tokens are billed at the applicable model token rates. + +**Credits settlement:** B.AI converts charges at `1 USD = 1,000,000 Credits` and deducts Credits from the account balance. + +:::info Pricing note +Model prices in the documentation are based on the model providers' official list prices and serve as B.AI standard reference prices. B.AI may offer discounts or limited-time promotions on this basis; offer details are shown in [Promotions and Pricing Updates](../promotions-and-pricing-notices.md) and the website's discount groups. Applicable prices, offer terms, and final charges are subject to the platform display and actual billing records. +::: diff --git a/docs/llmservice/models/hy4-flash.md b/docs/llmservice/models/hy4-flash.md new file mode 100644 index 00000000..11e0b16e --- /dev/null +++ b/docs/llmservice/models/hy4-flash.md @@ -0,0 +1,55 @@ +# Hy4 Flash + +## Overview + +[Hy4 Flash](https://intl.cloud.tencent.com/document/product/1300/80695) is Tencent's lightweight Hy4-series model for everyday productivity and high-volume workloads. It combines text and image understanding with a 1M-token context window, deep reasoning, and tool use. + +## Key Features + +- **Everyday Productivity:** Designed for high-volume office tasks such as drafting, summarization, and information processing. +- **Long-Context Analysis:** Works with extensive documents, reference material, and conversation history within a 1M-token context window. +- **Visual Understanding:** Reads text in images, interprets charts, and analyzes screenshots alongside written instructions. +- **Flexible Reasoning:** Enables deep thinking by default and allows it to be disabled for simpler requests. +- **Connected Workflows:** Supports function calling, preserved thinking, and structured output for tasks that combine reasoning with external tools. + +## Best Use Cases + +- **Office Assistance:** Draft correspondence, summarize reports, and organize information across routine business tasks. +- **Document and Chart Analysis:** Extract information from scanned pages, interpret charts, and compare images with written material. +- **Coding Assistance:** Explain code, investigate bugs, and support code generation or refactoring with relevant project context. +- **Workflow Automation:** Use connected tools to retrieve information, process results, and prepare structured responses across multiple steps. + +## Capabilities and Limitations + +| Capability | Description | +| :--- | :--- | +| **Input and Output** | Text and image input; text output, including code and structured responses. | +| **Reasoning** | Deep thinking is enabled by default and can be disabled; supports preserved thinking across tool interactions. | +| **Context Window** | 1M tokens. | +| **Maximum Input** | 960,000 tokens. | +| **Maximum Output** | 64,000 tokens. | +| **Tool Use** | Function calling for external tools and multi-step workflows. | +| **Structured Output** | Supports structured responses for extraction and downstream processing. | +| **Image Input** | PNG, JPEG, WEBP, and static GIF; up to 10 MB per image and 600 images per request, including conversation history, subject to token limits. | + +### Known Limitations + +- Images are internally resized to approximately 2048 x 2048 pixels, and inputs exceeding 5500 x 5500 pixels are rejected; crop relevant regions when small text or fine detail matters. +- Executing code, editing files, or operating applications requires an environment with the appropriate external tools and permissions. +- For best results, tool workflows using preserved thinking should retain the model's unmodified reasoning history between requests. + +## Standard Pricing + +The token prices below are shown in USD per 1 million tokens; web search is billed in USD per use. + +| Model | Input
(USD / 1M Tokens) | Cache Write
(USD / 1M Tokens) | Cache Read
(USD / 1M Tokens) | Output
(USD / 1M Tokens) | Web Search
(USD / use) | +| :--- | ---: | ---: | ---: | ---: | ---: | +| **Hy4 Flash** | `$0.07` | `$0.07` | `$0.003` | `$0.281` | - | + +**Cache writes:** B.AI bills cache writes at the input rate (1x). + +**Credits settlement:** B.AI converts charges at `1 USD = 1,000,000 Credits` and deducts Credits from the account balance. + +:::info Pricing note +Model prices in the documentation are based on the model providers' official list prices and serve as B.AI standard reference prices. B.AI may offer discounts or limited-time promotions on this basis; offer details are shown in [Promotions and Pricing Updates](../promotions-and-pricing-notices.md) and the website's discount groups. Applicable prices, offer terms, and final charges are subject to the platform display and actual billing records. +::: diff --git a/docs/llmservice/models/hy4.md b/docs/llmservice/models/hy4.md index cde895df..2c2544ae 100644 --- a/docs/llmservice/models/hy4.md +++ b/docs/llmservice/models/hy4.md @@ -16,10 +16,12 @@ Hy4 token charges are billed at 50% of the standard reference price, including i | Billing Item | Promotional Price (USD / 1M Tokens) | | :--- | ---: | -| Input | `$0.42` | -| Cache Write | `$0.42` | -| Cache Read | `$0.02` | -| Output | `$1.25` | +| Input | `$0.4170` | +| Cache Write | `$0.4170` | +| Cache Read | `$0.0210` | +| Output | `$1.2505` | + +Each promotional price is 50% of its official list price, shown to four decimal places. The standard pricing table below continues to show original prices. See [Promotions and Pricing Updates](../promotions-and-pricing-notices.md) for the offer. The promotion period, actual settlement prices, and final billing are subject to the platform display. diff --git a/docs/llmservice/pricing-and-usage.md b/docs/llmservice/pricing-and-usage.md index 0031095e..ace56d3b 100644 --- a/docs/llmservice/pricing-and-usage.md +++ b/docs/llmservice/pricing-and-usage.md @@ -44,6 +44,7 @@ The token prices below are shown in USD per 1 million tokens; web search is bill | Qwen3.7-Max | `$1.65` | `$1.65` | `$0.33` | `$4.951` | - | | Qwen3.7-Flash | `$0.03` | `$0.03` | `$0.006` | `$0.13` | - | | Qwen3.6-27B | `$0.19` | `$0.19` | `$0.019` | `$2.99` | - | +| Hy4 Flash | `$0.07` | `$0.07` | `$0.003` | `$0.281` | - | | Hy4 | `$0.834` | `$0.834` | `$0.042` | `$2.501` | - | | Hy4 Preview | `$0.834` | `$0.834` | `$0.042` | `$2.501` | - | | Hy3 | `$0.132` | `$0.132` | `$0.033` | `$0.528` | - | @@ -63,6 +64,8 @@ The token prices below are shown in USD per 1 million tokens; web search is bill | DeepSeek V4 Pro | Off-Peak `$0.66`
Peak `$1.32` | Off-Peak `$0.66`
Peak `$1.32` | Off-Peak `$0.022`
Peak `$0.044` | Off-Peak `$1.98`
Peak `$3.96` | - | | Grok 4.6 | `$2.00` | `$2.00` | `$0.50` | `$6.00` | - | | Grok 4.5 | `$2.00` | `$2.00` | `$0.30` | `$6.00` | - | +| GPT-6.2 Astra | `$8.00` | 30m: `$10.00`
12h: `$20.00` | `$0.40` | `$40.00` | `$0.01` | +| GPT-6.2 Sol | `$2.00` | 30m: `$2.50`
12h: `$5.00` | `$0.10` | `$10.00` | `$0.01` | | GPT-6.1 Terra | `$1.00` | 30m: `$1.25`
12h: `$2.50` | `$0.05` | `$5.00` | `$0.01` | | GPT-6.1 Sol | `$2.00` | 30m: `$2.50`
12h: `$5.00` | `$0.10` | `$10.00` | `$0.01` | | GPT-6 Astra | `$10.00` | 30m: `$12.50`
12h: `$25.00` | `$1.00` | `$50.00` | `$0.01` | @@ -115,7 +118,7 @@ The token prices below are shown in USD per 1 million tokens; web search is bill **Cache pricing:** `Cache Write` indicates the price charged when cache writing occurs; it does not mean that all models use the same cache retention period. Cache policies, retention periods, long-context pricing, and extended caching capabilities may vary by model. If a model uses special caching rules, 1-hour cache write pricing, or time-based pricing, refer to its model detail page. -**GPT cache-write lifetimes:** GPT-5.6 Sol, Terra, and Luna; GPT-6 Astra, Sol, and Luna; and GPT-6.1 Sol and Terra distinguish 30-minute and 12-hour cache writes, priced at 1.25x and 2.5x the applicable input rate, respectively. These write rates replace the ordinary input charge for those tokens, rather than adding to it. Cache-read rates are the same for both lifetimes. +**GPT cache-write lifetimes:** GPT-5.6 Sol, Terra, and Luna; GPT-6 Astra, Sol, and Luna; GPT-6.1 Sol and Terra; and GPT-6.2 Astra and Sol distinguish 30-minute and 12-hour cache writes, priced at 1.25x and 2.5x the applicable input rate, respectively. These write rates replace the ordinary input charge for those tokens, rather than adding to it. Cache-read rates are the same for both lifetimes. **Long-context pricing:** Some models use tiered long-context pricing. The table shows their base-tier rates; see the corresponding model detail pages for thresholds, full prices, and billing rules. @@ -140,7 +143,7 @@ Auto Mode is not a separately billable model. Each request is billed based on th ### Cache Pricing Notes -- **Cache Write:** The charge for tokens written into the prompt cache; rates depend on the model and cache lifetime. For the GPT-5.6, GPT-6, and GPT-6.1 models listed above, 30-minute writes cost 1.25x the applicable input rate and 12-hour writes cost 2.5x, replacing the ordinary input charge for those tokens. See each model detail page for other models' write rates and lifetime rules. +- **Cache Write:** The charge for tokens written into the prompt cache; rates depend on the model and cache lifetime. For the GPT-5.6, GPT-6, GPT-6.1, and GPT-6.2 models listed above, 30-minute writes cost 1.25x the applicable input rate and 12-hour writes cost 2.5x, replacing the ordinary input charge for those tokens. See each model detail page for other models' write rates and lifetime rules. - **Cache Read:** The discounted cost when cached tokens are reused in subsequent requests. - **Example with Caching:** If you use Claude Sonnet 4.6 with 1000 tokens cached: - First request (cache write): `1000 × 3.75 = 3,750 credits` diff --git a/docs/llmservice/promotions-and-pricing-notices.md b/docs/llmservice/promotions-and-pricing-notices.md index 9a9fbb59..f5a82f5b 100644 --- a/docs/llmservice/promotions-and-pricing-notices.md +++ b/docs/llmservice/promotions-and-pricing-notices.md @@ -10,6 +10,27 @@ This page summarizes active and announced upcoming limited-time offers and prici This section shows active and announced upcoming promotions: free offers appear first, followed by discounts from highest to lowest. ::: + + +**Offer ends at 12:00 noon on November 30, 2026 (Beijing Time, UTC+8).** + +During the promotion, Hy4 Flash token charges are billed at 50% of the standard reference price, including input, output, cache writes, and cache reads. This offer applies only to `hy4-flash`. + +| Billing Item | Promotional Price (USD / 1M Tokens) | +| :--- | ---: | +| Input | `$0.035` | +| Cache Write | `$0.035` | +| Cache Read | `$0.0015` | +| Output | `$0.1405` | + +After the offer ends, usage is billed at the standard reference prices. The [Pricing and Usage](./pricing-and-usage.md) table and [model details](./models/hy4-flash.md) continue to show original prices. Applicable terms and final charges are subject to the platform display and actual billing records. + + @@ -32,11 +55,17 @@ The [Pricing and Usage](./pricing-and-usage.md) table and [model details](./mode variant="discount" title="DeepSeek-V4.1-Flash" status="Limited-Time Discount" - detail="60% from Oct 4, 10:00 SGT" + detail="50% OFF" > -The offer takes effect at 10:00 on October 4, 2026 (SGT, UTC+8). -From that time, the promotional price changes in step with DeepSeek's time-based pricing and is billed at 60% of the applicable Off-Peak or Peak standard price. +During the promotion, input, output, cache writes, and cache reads are billed at 50% of the applicable Off-Peak or Peak standard reference price. Promotional prices change in step with DeepSeek's time-based pricing. + +The promotional prices below are in USD per 1 million tokens. + +| Billing Period | Input | Cache Write | Cache Read | Output | +| :--- | ---: | ---: | ---: | ---: | +| Off-Peak | `$0.075` | `$0.075` | `$0.0015` | `$0.30` | +| Peak | `$0.15` | `$0.15` | `$0.003` | `$0.60` | The [Pricing and Usage](./pricing-and-usage.md) table and [model details](./models/deepseek-v4-1-flash.md) continue to show standard reference prices. Actual settlement and final billing are subject to the platform display. diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current.json b/i18n/zh-Hans/docusaurus-plugin-content-docs/current.json index 6bfe6488..f965e41e 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current.json +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current.json @@ -195,6 +195,22 @@ "message": "余额 API", "description": "The label for the doc item Balance API in sidebar docsSidebar" }, + "sidebar.docsSidebar.doc.GPT-6.2 Astra": { + "message": "GPT-6.2 Astra", + "description": "The label for the GPT-6.2 Astra model document in sidebar docsSidebar" + }, + "sidebar.docsSidebar.doc.GPT-6.2 Sol": { + "message": "GPT-6.2 Sol", + "description": "The label for the GPT-6.2 Sol model document in sidebar docsSidebar" + }, + "sidebar.docsSidebar.doc.Hy4 Flash": { + "message": "Hy4 Flash", + "description": "The label for the Hy4 Flash model document in sidebar docsSidebar" + }, + "sidebar.docsSidebar.doc.MiniMax Image Generation API": { + "message": "MiniMax 图片生成 API", + "description": "The label for the MiniMax image generation API document in sidebar docsSidebar" + }, "sidebar.docsSidebar.doc.Gemini 4 Hydrogen": { "message": "Gemini 4 Hydrogen", "description": "The label for the Gemini 4 Hydrogen model document in sidebar docsSidebar" diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/api/API.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/api/API.md index 4c1cf3a7..9477f413 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/api/API.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/api/API.md @@ -2,13 +2,13 @@ B.AI 提供统一的大语言模型 API,兼容 OpenAI Chat Completions、OpenAI Responses 和 Anthropic Messages 协议,同时提供兼容 TypeSafe System One 协议的 Decisions API。开发者可以使用同一个 B.AI API Key 接入不同协议,并根据应用或客户端的要求选择对应端点。 -B.AI 还提供异步[视频生成 API](./videos.md),支持创建任务、查询状态及下载已完成的视频。 +B.AI 还提供 [MiniMax 图像生成 API](./minimax-image-generation.md),支持同步文生图、参考图编辑及可选的 SSE 流式输出;异步[视频生成 API](./videos.md)支持创建任务、查询状态及下载已完成的视频。 [充值 API](./recharges.md) 使用独立的服务地址 `https://chat.b.ai`,用于创建及查询加密货币充值订单。希望通过 Agent 使用,请查看[充值 Skill 使用指南](./recharge-skill-guide.md)。 - **API 版本:** `v1` - **生产环境 Base URL:** `https://api.b.ai/v1` -- **请求格式:** `application/json` +- **请求格式:** 默认使用 `application/json`;图像编辑还支持 `multipart/form-data`,参考图上传使用 `multipart/form-data`。 - **字符编码:** UTF-8 - **文本生成流式传输:** Server-Sent Events(SSE) @@ -52,7 +52,7 @@ curl https://api.b.ai/v1/responses \ B.AI 支持以下两种认证请求头。两者使用平台签发的同一种 API Key,选择其中一种即可。 -视频生成请使用[视频生成 API](./videos.md)示例中的 Bearer 认证;本页暂未说明该端点是否支持 `x-api-key`。 +图像生成、编辑、参考图上传及视频生成,请使用 [MiniMax 图像生成 API](./minimax-image-generation.md)和[视频生成 API](./videos.md)示例中的 Bearer 认证;本页暂未说明这些端点是否支持 `x-api-key`。 充值端点同样使用 Bearer 认证,不要将模型服务的 `x-api-key` 替代方式直接套用于充值请求。 @@ -94,6 +94,9 @@ x-api-key: | `POST` | `/responses` | OpenAI Responses | Agent、推理、工具调用及 Codex 等场景 | | `POST` | `/chat/completions` | OpenAI Chat Completions | 通用聊天补全及现有 OpenAI 兼容应用 | | `POST` | `/messages` | Anthropic Messages | Claude SDK、Claude Code 等 Anthropic 兼容应用 | +| `POST` | [`/images/generations`](./minimax-image-generation.md) | OpenAI SDK 兼容,参数以模型专属文档为准 | 同步生成 MiniMax 图片,可选 SSE 流式输出 | +| `POST` | [`/images/edits`](./minimax-image-generation.md) | OpenAI SDK 兼容,参数以模型专属文档为准 | 使用参考图编辑 MiniMax 图片,支持 JSON 或 multipart 表单 | +| `POST` | [`/files/upload`](./minimax-image-generation.md#上传参考图) | - | 以 `purpose=image_generation_input` 上传参考图,用于 `mm_file://` 引用 | | `POST` | [`/videos`](./videos.md) | - | 创建异步视频生成任务 | | `GET` | [`/videos/{task_id}`](./videos.md) | - | 查询视频任务的生成及计费状态 | | `GET` | [`/videos/{task_id}/content`](./videos.md) | - | 通过鉴权下载已完成生成和结算的视频 | diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/api/minimax-image-generation.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/api/minimax-image-generation.md new file mode 100644 index 00000000..708d505a --- /dev/null +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/api/minimax-image-generation.md @@ -0,0 +1,398 @@ +# MiniMax 图像生成 API + +B.AI 图像 API 支持文生图与参考图编辑,同步返回生成结果: + +**提交请求 → 读取响应 → 下载图片。** + +开启 `stream` 后,图片按完成顺序逐张推送,不必等待整批结束。 + +本文档介绍 **MiniMax-H3-Image** 与 **MiniMax-H3-Image-Highspeed** 的调用方式。模型能力与标准价格见[共用详情页](../image-models/minimax-h3-image.md)。 + +## 准备工作 + +### 接口地址 + +```text +https://api.b.ai +``` + +### 鉴权 + +所有接口均需携带 API Key: + +```http +Authorization: Bearer YOUR_API_KEY +``` + +支持个人 API Key 和 Team API Key。 + +以下示例使用环境变量: + +```bash +export BAI_API_KEY="YOUR_API_KEY" +``` + +图像生成会产生费用,请确保账户余额充足。 + +### 模型名称 + +| 模型 | 请求中的 `model` | +| --- | --- | +| MiniMax-H3-Image | `minimax-h3-image` | +| MiniMax-H3-Image-Highspeed | `minimax-h3-image-highspeed` | + +`minimax-h3-image-highspeed` 是 `minimax-h3-image` 的高速版本,参数与限制完全一致,仅切换 `model` 字段。 + + +实际可调用的模型以当前账户开放范围为准,可通过 `GET https://api.b.ai/v1/models` 查询当前 API 凭证关联的模型 ID。 + +## 1. 创建图像任务(文生图) + +```http +POST https://api.b.ai/v1/images/generations +``` + +提交 JSON 请求,服务端同步生成并返回结果。**服务端最长等待 600 秒,请将客户端超时设置为不小于 600 秒。** + +### 请求示例 + +```bash +curl https://api.b.ai/v1/images/generations \ + -H "Authorization: Bearer ${BAI_API_KEY}" \ + -H "Content-Type: application/json" \ + -d '{ + "model": "minimax-h3-image", + "prompt": "一只橘猫躺在窗台上晒太阳,午后暖光,胶片质感", + "size": "2720x1536", + "n": 1, + "response_format": "url" + }' +``` + +### 主要参数 + +| 参数 | 类型 | 说明 | +| --- | --- | --- | +| `model` | string | 必填,模型名称 | +| `prompt` | string | 必填,画面描述,最长 32000 字符;空或仅空白内容返回 `400` | +| `n` | integer | 生成图片数量,取值 1–10,默认 `1` | +| `size` | string | 输出尺寸,默认 `auto`;与 `aspect_ratio` / `area` 互斥,见下文「输出尺寸」 | +| `aspect_ratio` | string | 画面比例,默认 `auto`;`X:Y` 中 X、Y 为 1–300 的整数,比例需在 1:3 ~ 3:1 之间(闭区间) | +| `area` | string | 面积档位 `1K` / `2K` / `4K`,默认 `4K`;仅在 `size` 为 `auto` 或省略时可设置 | +| `output_format` | string | `jpeg`(默认)/ `jpg` / `png` / `webp`;`jpg` 等价于 `jpeg`,响应中统一返回 `jpeg` | +| `response_format` | string | `url`(默认)/ `b64_json`;`b64_json` 不支持流式 | +| `output_compression` | integer | 压缩质量,取值 0–100,默认 `95`;仅对 `jpeg` / `webp` 生效,`png` 忽略该参数 | +| `disable_prompt_enhanced` | boolean | 是否关闭提示词增强,默认 `false`(开启) | +| `stream` | boolean | 是否流式返回,默认 `false` | + +### 输出尺寸 + +尺寸有两种写法,只能二选一。设置 `size` 为 `WIDTHxHEIGHT` 时再传 `aspect_ratio` 或 `area`(哪怕是 `auto`)会返回 `400`。 + +**宽高模式:** + +```json +{ "size": "2720x1536" } +``` + +面积(宽 × 高)需在 655,360 ~ 20,000,000 像素之间,比例在 1:3 ~ 3:1 之间(闭区间),否则返回 `400`。**尺寸不会被缩放或取整**,不符合即报错。 + +**比例 + 面积档位模式:** + +```json +{ "aspect_ratio": "16:9", "area": "2K" } +``` + +`area` 的目标面积分别为 1024 × 1024、2048 × 2048、4096 × 4096 像素,服务端按比例换算实际宽高。各比例下的实际输出尺寸: + +| 画面比例 | `1K` | `2K` | `4K` | +| --- | --- | --- | --- | +| 1:1 | `1024x1024` | `2048x2048` | `4096x4096` | +| 4:3 / 3:4 | `1184x880` / `880x1184` | `2368x1760` / `1760x2368` | `4736x3552` / `3552x4736` | +| 16:9 / 9:16 | `1360x768` / `768x1360` | `2720x1536` / `1536x2720` | `5472x3072` / `3072x5472` | +| 3:1 / 1:3 | `1776x592` / `592x1776` | `3552x1184` / `1184x3552` | `7104x2368` / `2368x7104` | + +每张图片的实际尺寸见响应中的 `data[].size`。 + +### 提示词增强 + +文生图默认开启提示词增强,服务端会改写并扩写 prompt,实际使用的提示词在 `data[].revised_prompt` 中返回。 + +- `disable_prompt_enhanced: true`:直接使用原始 `prompt`,此时必须显式给出宽高(`size` 为 `WIDTHxHEIGHT`),或给出固定比例(`size` 为 `auto`/省略且 `aspect_ratio` 为 `X:Y`),否则返回 `400`。 +- 关闭增强后,模型仅读取前约 4096 个 token,其余内容不生效。 +- 调优流程:取 `revised_prompt`,自行修改后作为新请求的 `prompt`,并设置 `disable_prompt_enhanced: true`,即可复用或调整增强后的提示词,但不保证生成完全相同的图片。 + +### 创建响应 + +返回 `200`,`data` 始终包含 `n` 个元素,顺序与请求一致。以下示例展示 **`n=2` 时一张成功、一张失败**的响应: + +```json +{ + "created": 1792308678, + "data": [ + { + "url": "https://example.com/h3-image/output-0.jpg", + "size": "2720x1536", + "revised_prompt": "午后的暖光穿过木质窗框落在窗台上,一只橘猫侧躺着晒太阳,半眯着眼睛,毛发边缘泛着金色光泽,背景是虚化的室内绿植,胶片颗粒,柔和暖色调" + }, + { + "error": { + "code": "1027", + "message": "output image failed content safety check" + } + } + ], + "output_format": "jpeg", + "usage": { + "generated_images": 1, + "total_tokens": 7254, + "input_tokens": 3174, + "output_tokens": 4080, + "input_tokens_details": { + "text_tokens": 3174, + "image_tokens": 0 + }, + "output_tokens_details": { + "image_tokens": 4080 + } + }, + "request_id": "021792308678142a2c883cf675b9804d" +} +``` + +响应体中的 `request_id` 为上游生成标识。**反馈问题时请提供响应头 `X-Oneapi-Request-Id`**,平台流水与日志均以此为准,每个响应都会携带。 + +### 部分失败 + +只要有任意一张图生成成功,接口就返回 `200`。`data` 中失败的元素(含被内容安全拦截的图)只包含 `error` 字段,没有 `url`。实际成功数量见 `usage.generated_images`,**只有成功产出的图片计费**。 + +全部失败时返回错误响应,并附带逐图失败原因与 `usage`: + +- `422`:全部图片未通过内容安全检查 +- `500`:其他原因 + +### 重复提交与重试 + +该接口**不是幂等接口**。请求一旦发出,B.AI 会完成生成并按实际成功的图片结算,即使客户端超时或断开;重试会再次生成并再次扣费。 + +网络超时或暂时异常时,不要直接重发。推荐做法: + +- 使用 OpenAI SDK 时设置 `max_retries=0`,关闭默认自动重试; +- 自行记录响应头 `X-Oneapi-Request-Id` 与业务侧任务标识,先确认上一笔是否已扣费,再决定是否补发。 + +## 2. 参考图编辑 + +```http +POST https://api.b.ai/v1/images/edits +``` + +在文生图的基础上传入 1–16 张参考图,可对主体、场景、风格等进行编辑。除提示词增强行为外,其余参数与文生图一致。 + +### 请求示例 + +```bash +curl https://api.b.ai/v1/images/edits \ + -H "Authorization: Bearer ${BAI_API_KEY}" \ + -H "Content-Type: application/json" \ + -d '{ + "model": "minimax-h3-image", + "prompt": "把图 1 中的猫替换成图 2 中的柴犬,保持背景不变", + "images": [ + { "image_url": "https://example.com/cat.jpg" }, + { "image_url": "https://example.com/dog.png" } + ], + "size": "auto", + "response_format": "url" + }' +``` + +也支持 `multipart/form-data`,与 OpenAI SDK 的 `images.edit` 兼容,文件上传顺序即图片序号(图 1、图 2……),prompt 中可用「图 1」「图 2」引用。 + +### 参考图限制 + +| 项目 | 限制 | +| --- | --- | +| 格式 | JPG、JPEG、PNG、WEBP、HEIC、HEIF | +| 单文件大小 | ≤ 64 MiB | +| 请求体总大小 | ≤ 64 MiB | +| 宽高范围 | \[128, 8192] px | +| 长短边比例 | ≤ 4:1 | +| 数量 | 1 ~ 16 | + +`images[].image_url` 支持三种来源: + +- 公网可访问的 URL(推荐); +- `mm_file://{file_id}`,引用已上传文件的标识; +- `data:image/;base64,` data URI(`` 小写)。 + +Base64 编码后体积约为原文件的 4/3,请求体容易触顶。**请求体可能超过 64 MiB 时,请改用公网 URL 或 `mm_file://`。** + +### 上传参考图 + +使用 `mm_file://` 前,先通过文件上传接口传入参考图,`purpose` 固定为 `image_generation_input`,再用返回的 `file_id` 拼出 `mm_file://{file_id}`。 + +```bash +curl https://api.b.ai/v1/files/upload \ + -H "Authorization: Bearer ${BAI_API_KEY}" \ + -F "purpose=image_generation_input" \ + -F "file=@cat.jpg" +``` + +### 与文生图的差异 + +- `images` 为必填项。 +- **始终开启提示词增强**,不支持 `disable_prompt_enhanced`。 +- `aspect_ratio` 为 `auto` 时,由提示词增强结合参考图内容决定。 +- 提示词增强的 token 计入 `usage.input_tokens_details.text_tokens`。 + +## 3. 流式输出 + +在文生图或参考图编辑请求中设置 `stream: true`,服务端以 SSE(`text/event-stream`)逐张推送结果。**仅支持 `response_format: "url"`。** + +### 请求示例 + +```bash +curl -N https://api.b.ai/v1/images/generations \ + -H "Authorization: Bearer ${BAI_API_KEY}" \ + -H "Content-Type: application/json" \ + -d '{ + "model": "minimax-h3-image", + "prompt": "一只橘猫躺在窗台上晒太阳,午后暖光,胶片质感", + "size": "2720x1536", + "n": 3, + "stream": true + }' +``` + +### 事件类型 + +| 事件 | 说明 | +| --- | --- | +| `.partial_succeeded` | 单张图片生成成功,携带 `image_index`、`url`、`size`、`output_format`、`revised_prompt` | +| `.partial_failed` | 单张图片失败,携带 `image_index`、`code`、`message` | +| `.completed` | 全部结束且至少一张成功,携带 `usage` 与 `request_id` | +| `error` | 无任何图片成功(含提交生成前失败),不计费,`usage` 各字段均为 0 | + +`` 在文生图为 `image_generation`,在参考图编辑为 `image_edit`。 + +事件按完成顺序推送,用 `image_index`(从 0 开始,范围 `[0, n-1]`)对应图片。等待期间服务端每 15 秒发送一行 `: keepalive` 注释,客户端可直接忽略。 + +**解析 SSE 前先判断 HTTP 状态码**:响应头发出之前的错误(参数非法、鉴权失败、限流、余额不足)仍以常规 HTTP 错误返回,不会以 `error` 事件形式出现。 + +## 4. 下载图片 + +响应中的 `url` 需要自行下载并转存,**平台不保证链接长期有效**。生成后请及时保存到自己的存储。 + +```bash +curl --fail --location \ + "https://example.com/h3-image/output-0.jpg" \ + --output output-0.jpg +``` + +若使用 `response_format: "b64_json"`,则直接在 `data[].b64_json` 中拿到 Base64 数据,无需额外下载。该方式不支持流式,且受总面积限制: + +| `output_format` | `b64_json` 总面积上限 | 示例 | +| --- | --- | --- | +| `png` | 20,000,000 px | 1 张任意尺寸图片 | +| `jpeg` / `webp` | 80,000,000 px | 4 张 4K,或 10 张 2K | + +超出上限返回 `400`,建议改用 `url`。 + +## OpenAI SDK 兼容 + +两个接口均兼容 OpenAI SDK,只需把 `base_url` 指向 B.AI: + +```python +import os +from openai import OpenAI + +client = OpenAI( + base_url="https://api.b.ai/v1", + api_key=os.environ["BAI_API_KEY"], + timeout=600, + max_retries=0, # 接口非幂等:关闭自动重试,避免重复生成与扣费 +) + +result = client.images.generate( + model="minimax-h3-image", + prompt="一只橘猫躺在窗台上晒太阳,午后暖光,胶片质感", + size="2720x1536", + response_format="url", +) + +for i, item in enumerate(result.data): + print(i, item.url) # 失败的图片 url 为 None +``` + +## 用量与限流 + +### 用量 + +- 用量统计在响应的 `usage` 字段中,**只计入成功生成的图片**,失败或被安全拦截的图片不计入。 +- `input_tokens` 为文本提示词与参考图消耗的输入 token,`output_tokens` 为生成图片消耗的输出 token,`total_tokens` 为两者之和。 +- 提示词增强消耗的输入 token 计入 `usage.input_tokens`,**按张数计(`n` 张计 `n` 次)**。实际计费用量以响应中的 `usage` 为准,仅统计成功生成的图片。 + +两个模型的 Token 单价详见[图像生成模型定价](../image-models/pricing.md)。 + +### 限流 + +图像接口按**账户**限流,**按请求次数**计: + +| 项目 | 限额 | +| --- | --- | +| 每个账户每分钟请求数 | 16 | + +两个 MiniMax 模型与 GPT-Image-2 **共用**这一配额。 + +请求次数与 `n` 无关,`n=10` 仍算 1 次请求。触发限流时返回 `429`(`code: persistent_image_rate_limited`),请降低请求频率后重试。 + +## 常见错误 + +错误分两层:平台接口级错误以 HTTP 状态码返回;单张图片的失败原因通过 `data[].error` 返回。 + +### 平台接口级错误 + +| HTTP 状态码 | 常见原因 | +| --- | --- | +| `400` | 请求参数不合法、携带了本文档未列出的参数、余额不足 | +| `401` | API Key 无效或已过期 | +| `403` | 权限或 Team 成员额度受限 | +| `404` | 端点或模型不存在,或当前身份无权访问 | +| `429` | 请求次数超限 | +| `500` | 服务端异常 | +| `502` / `503` | 服务暂时异常 | + +`400` 常见的两类细分: + +| 错误标识 / 提示 | 含义 | 处理建议 | +| --- | --- | --- | +| `unknown image parameter`(错误提示) | 携带了本文档未列出的参数(例如 `seed`) | 移除该参数后重试 | +| `code: insufficient_user_quota` | 账户余额不足 | 充值后重试 | + +错误响应采用统一结构: + +```json +{ + "error": { + "code": "", + "message": "Invalid token (request id: 2026111307415255722563c955d568zj7buxCT)", + "type": "api_error" + } +} +``` + +**反馈问题时请提供响应头 `X-Oneapi-Request-Id`**,平台流水与日志均以此为准。部分错误(如 `429`)的 `message` 中不含 request id。 + +### 单张图片级错误 + +`data[].error.code` 为单张图片的错误码,常见值如下: + +| 错误码 | 含义 | 处理建议 | +| --- | --- | --- | +| `1000` | 未知错误 / 服务端异常 | 稍后重试 | +| `1001` | 请求超时 | 稍后重试 | +| `1026` | 输入内容被判定为敏感 | 修改输入内容 | +| `1027` | 输出图片被判定为敏感 | 修改输入内容 | +| `2013` | 参数非法 | 检查请求参数 | + +**失败重试建议**:图像接口不是幂等接口,重试会重新生成并重新扣费。发生超时或网络异常时,先确认上一笔是否已产生费用,再决定是否重发;只应重试 5xx 与明确的限流错误,参数错误(`400`)、鉴权错误(`401`)、余额不足(`400`)、安全检查错误(`422`)重试无意义。 diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/image-models/minimax-h3-image.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/image-models/minimax-h3-image.md index 3adcd1b8..575d451a 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/image-models/minimax-h3-image.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/image-models/minimax-h3-image.md @@ -4,6 +4,8 @@ [MiniMax-H3-Image](https://www.minimax.io/blog/minimax-h3-image) 是 MiniMax 于 2026 年 11 月 11 日发布的 H3 系列开放权重图像生成与编辑模型,结合细致的指令遵循、多参考图组合与原生 4K 生成能力,适用于创意制作和产品设计工作流。 +文生图、参考图编辑、参考图上传、流式输出和错误处理的调用方式,详见 [MiniMax 图像生成 API](../api/minimax-image-generation.md)。 + ## 模型版本 | 模型 | 说明 | diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/models/deepseek-v4-1-flash.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/models/deepseek-v4-1-flash.md index 5b9e3376..b2c8fe4f 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/models/deepseek-v4-1-flash.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/models/deepseek-v4-1-flash.md @@ -14,11 +14,17 @@ B.AI 将逐步把使用 `DeepSeek-V4-Flash` 和 `DeepSeek-V4-Flash-Vision-Exp` variant="discount" title="DeepSeek-V4.1-Flash" status="限时折扣" - detail="10 月 4 日 10:00 SGT 起 6 折" + detail="5 折" > -活动于 2026 年 10 月 4 日 10:00(SGT,新加坡时间,UTC+8)起生效。 -自生效时间起,活动价格随 DeepSeek 空闲时段与高峰时段同步变化,各时段均按对应标准价的 60% 结算。 +活动期间,输入、输出、缓存写入和缓存读取均按对应空闲时段或高峰时段标准参考价的 50% 结算,活动价格随 DeepSeek 峰谷计价同步变化。 + +以下活动价格均以美元计价,单位为每 100 万 Token。 + +| 计费时段 | 输入 | 缓存写入 | 缓存读取 | 输出 | +| :--- | ---: | ---: | ---: | ---: | +| 空闲时段 | `$0.075` | `$0.075` | `$0.0015` | `$0.30` | +| 高峰时段 | `$0.15` | `$0.15` | `$0.003` | `$0.60` | 下方价格表继续展示标准参考价,实际结算价格及最终账单以平台页面展示为准。 diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/models/gpt-6-2-astra.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/models/gpt-6-2-astra.md new file mode 100644 index 00000000..6a56eb7d --- /dev/null +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/models/gpt-6-2-astra.md @@ -0,0 +1,62 @@ +# GPT-6.2 Astra + +## 概述 + +GPT-6.2 Astra 是 OpenAI 面向高难度软件工程和专业项目的 GPT-6.2 推理模型,于 [2026 年 11 月 17 日发布](https://developers.openai.com/api/docs/changelog)。它结合文本与图像理解、可调节推理和工具使用能力,用于规划和完成复杂工作。 + +## 核心特性 + +- **复杂项目处理**:规划并执行项目,根据新增信息调整处理方式。 +- **软件工程**:结合代码执行和编辑工具构建、修订软件,并辅助实现和验证。 +- **视觉计算机操作**:解读截图,并配合计算机操作工具跨应用完成任务。 +- **长工作上下文**:1.05M Token 上下文窗口可容纳大量源材料、代码及对话历史。 +- **智能体任务委派**:支持 Responses API Multi-agent 测试版,将独立子任务交给子智能体处理。 +- **清晰写作**:默认倾向于简洁直接的表达,可根据受众调整语气和细节。 + +## 适用场景 + +- **复杂软件项目**:需要跨组件反复测试的实现、调试和代码审核工作。 +- **研究与技术决策**:比较证据、检验假设并权衡不同方案的开放式分析。 +- **专业交付物**:将详细需求和参考材料整理成报告、文档或应用,并持续迭代修订。 +- **计算机工作流**:通过界面、文件和连接的工具协调一系列操作。 + +## 能力与限制 + +| 能力 | 说明 | +| :--- | :--- | +| **推理** | 支持 `low`、`medium`、`high`、`xhigh` 和 `max`;不支持 `none` 和 `minimal`。 | +| **多模态** | 支持文本和图像输入、文本输出;不支持原生音频和视频。 | +| **上下文窗口** | [1,050,000 Token](https://developers.openai.com/api/docs/models/gpt-6.2-astra),由输入和生成的 Token 共同占用。 | +| **最大输入** | 922,000 Token。 | +| **最大输出** | 128,000 Token,包含推理和可见输出。 | +| **工具使用** | 通过 Responses API 中的工具支持函数调用、网页与文件搜索、代码执行、计算机操作、MCP 和图像生成。 | +| **结构化输出** | 支持 Structured Outputs 和流式输出。 | +| **提示词缓存** | 通过 Responses API 支持隐式和显式缓存,最低有效期为 30 分钟或 12 小时。 | +| **知识截止时间** | 2026 年 5 月 18 日。 | + +### 已知限制 + +- 工具调用需要使用 Responses API;Chat Completions 支持不含工具的请求。 +- 不支持采样和对数概率控制;不支持微调。 +- 推理会消耗输出预算,并可能增加延迟;输出预算不足时,响应可能在生成可见回答前就已处于未完成状态。 +- 修改较早的对话内容或切换到较小的模型,可能丢弃此前的推理内容,降低上下文连续性并增加重复工作。 + +## 标准价格 + +以下 Token 价格均以美元计价,单位为每 100 万 Token;网页搜索按次计费。 + +| 上下文档位 | 输入
(USD / 1M Tokens) | 30 分钟缓存写入
(USD / 1M Tokens) | 12 小时缓存写入
(USD / 1M Tokens) | 缓存读取
(USD / 1M Tokens) | 输出
(USD / 1M Tokens) | 网页搜索
(USD / 次) | +| :--- | ---: | ---: | ---: | ---: | ---: | ---: | +| 输入不超过 272K Token | `$8.00` | `$10.00` | `$20.00` | `$0.40` | `$40.00` | `$0.01` | +| 输入超过 272K Token | `$16.00` | `$20.00` | `$40.00` | `$0.80` | `$60.00` | `$0.01` | + +- 当输入超过 272K Token 时,高档费率适用于整次请求,而不只是超出门槛的部分。 +- [缓存写入费用](https://developers.openai.com/api/docs/guides/prompt-caching)适用于隐式和显式缓存,替代对应 Token 的普通输入费用,不重复收取。默认最低有效期为 30 分钟。30 分钟写入按对应输入价的 1.25 倍计费,12 小时为 2.5 倍;两种时长的缓存读取价格相同,均为对应输入价的 0.05 倍。 +- 推理 Token 按输出 Token 计费。 +- 网页搜索每次 `10,000 Credits`,即 `$0.01`,不受上下文档位影响。搜索内容 Token 按对应模型的 Token 价格计费。 + +**Credits 结算:** B.AI 按照 `1 USD = 1,000,000 Credits` 换算并扣除 Credits。 + +:::info 价格说明 +文档中的模型价格以模型提供方官方原价为基准,作为 B.AI 平台的标准参考价。平台可能在此基础上提供折扣或限时活动,相关优惠将在[活动与调整公告](../promotions-and-pricing-notices.md)及网站的折扣分组中展示。具体适用价格、优惠规则及最终费用,以平台页面展示和实际账单为准。 +::: diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/models/gpt-6-2-sol.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/models/gpt-6-2-sol.md new file mode 100644 index 00000000..c1d676b7 --- /dev/null +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/models/gpt-6-2-sol.md @@ -0,0 +1,62 @@ +# GPT-6.2 Sol + +## 概述 + +GPT-6.2 Sol 是 OpenAI 面向日常编程、专业工作和智能体工作流的 GPT-6.2 推理模型,于 [2026 年 11 月 17 日发布](https://developers.openai.com/api/docs/changelog)。它结合文本与图像理解、工具使用和长上下文能力,为复杂工作提供比 Astra 成本更低的选择。 + +## 核心特性 + +- **日常软件开发**:支持在现有代码库中修复缺陷、添加功能及完成其他开发工作。 +- **迭代任务执行**:处理需要持续测试和修订的多步骤任务。 +- **工具型智能体**:通过 Responses API 使用搜索、代码执行、计算机操作及连接的工具。 +- **可调节推理**:帮助应用平衡推理深度、响应时间和 Token 消耗;OpenAI 建议新接入时从 medium 强度开始。 +- **长工作上下文**:结合 1.05M Token 上下文窗口和提示词缓存,复用指令与参考资料。 +- **智能体任务委派**:支持 Responses API Multi-agent 测试版,将独立子任务交给子智能体处理。 + +## 适用场景 + +- **代码库维护**:根据明确的验收标准修复缺陷、添加范围明确的功能及修改代码。 +- **运营助手**:完成结合信息检索、应用交互和工具调用的重复性工作流。 +- **文档起草**:将笔记和源材料整理成待审核初稿,并根据反馈修改。 +- **文档与图像分析**:结合截图或其他图像审核长篇参考材料,输出结构化结论。 + +## 能力与限制 + +| 能力 | 说明 | +| :--- | :--- | +| **推理** | 支持 `low`、`medium`、`high`、`xhigh` 和 `max`;不支持 `none` 和 `minimal`。 | +| **多模态** | 支持文本和图像输入、文本输出;不支持原生音频和视频。 | +| **上下文窗口** | [1,050,000 Token](https://developers.openai.com/api/docs/models/gpt-6.2-sol),由输入和生成的 Token 共同占用。 | +| **最大输入** | 922,000 Token。 | +| **最大输出** | 128,000 Token,包含推理和可见输出。 | +| **工具使用** | 通过 Responses API 中的工具支持函数调用、网页与文件搜索、代码执行、计算机操作、MCP 和图像生成。 | +| **结构化输出** | 支持 Structured Outputs 和流式输出。 | +| **提示词缓存** | 通过 Responses API 支持隐式和显式缓存,最低有效期为 30 分钟或 12 小时。 | +| **知识截止时间** | 2026 年 6 月 1 日。 | + +### 已知限制 + +- 工具调用需要使用 Responses API;Chat Completions 支持不含工具的请求。 +- 不支持采样和对数概率控制;不支持微调。 +- 推理会消耗输出预算,并可能增加延迟;输出预算不足时,响应可能在生成可见回答前就已处于未完成状态。 +- 修改较早的对话内容或切换到较小的模型,可能丢弃此前的推理内容,降低上下文连续性并增加重复工作。 + +## 标准价格 + +以下 Token 价格均以美元计价,单位为每 100 万 Token;网页搜索按次计费。 + +| 上下文档位 | 输入
(USD / 1M Tokens) | 30 分钟缓存写入
(USD / 1M Tokens) | 12 小时缓存写入
(USD / 1M Tokens) | 缓存读取
(USD / 1M Tokens) | 输出
(USD / 1M Tokens) | 网页搜索
(USD / 次) | +| :--- | ---: | ---: | ---: | ---: | ---: | ---: | +| 输入不超过 272K Token | `$2.00` | `$2.50` | `$5.00` | `$0.10` | `$10.00` | `$0.01` | +| 输入超过 272K Token | `$4.00` | `$5.00` | `$10.00` | `$0.20` | `$15.00` | `$0.01` | + +- 当输入超过 272K Token 时,高档费率适用于整次请求,而不只是超出门槛的部分。 +- [缓存写入费用](https://developers.openai.com/api/docs/guides/prompt-caching)适用于隐式和显式缓存,替代对应 Token 的普通输入费用,不重复收取。默认最低有效期为 30 分钟。30 分钟写入按对应输入价的 1.25 倍计费,12 小时为 2.5 倍;两种时长的缓存读取价格相同,均为对应输入价的 0.05 倍。 +- 推理 Token 按输出 Token 计费。 +- 网页搜索每次 `10,000 Credits`,即 `$0.01`,不受上下文档位影响。搜索内容 Token 按对应模型的 Token 价格计费。 + +**Credits 结算:** B.AI 按照 `1 USD = 1,000,000 Credits` 换算并扣除 Credits。 + +:::info 价格说明 +文档中的模型价格以模型提供方官方原价为基准,作为 B.AI 平台的标准参考价。平台可能在此基础上提供折扣或限时活动,相关优惠将在[活动与调整公告](../promotions-and-pricing-notices.md)及网站的折扣分组中展示。具体适用价格、优惠规则及最终费用,以平台页面展示和实际账单为准。 +::: diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/models/hy4-flash.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/models/hy4-flash.md new file mode 100644 index 00000000..c9633434 --- /dev/null +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/models/hy4-flash.md @@ -0,0 +1,55 @@ +# Hy4 Flash + +## 概述 + +[Hy4 Flash](https://intl.cloud.tencent.com/document/product/1300/80695) 是腾讯 Hy4 系列的轻量模型,面向日常办公和高频、大规模任务,结合文本与图像理解、百万 Token 上下文、深度思考和工具调用能力。 + +## 核心特性 + +- **日常办公:** 面向撰写、总结和信息处理等高频办公任务。 +- **长上下文分析:** 可在百万 Token 上下文中处理大量文档、参考资料和对话历史。 +- **视觉理解:** 识别图像中的文字、理解图表,并结合文字指令分析截图。 +- **灵活推理:** 默认开启深度思考,简单请求可选择关闭。 +- **工具协作:** 支持函数调用、思考保留和结构化输出,适用于结合推理与外部工具的工作流。 + +## 适用场景 + +- **办公助手:** 撰写往来文书、总结报告并整理日常业务信息。 +- **文档与图表分析:** 从扫描件提取信息、解读图表,并结合文字资料比较图像内容。 +- **编程辅助:** 解释代码、排查问题,结合项目上下文辅助代码生成和重构。 +- **工作流自动化:** 借助外部工具检索信息、处理结果,并通过多步骤流程生成结构化响应。 + +## 能力与限制 + +| 能力 | 说明 | +| :--- | :--- | +| **输入与输出** | 支持文本和图像输入,输出文本,包括代码和结构化响应。 | +| **推理** | 默认开启深度思考,可关闭;支持在工具交互过程中保留思考历史。 | +| **上下文窗口** | 1M Token。 | +| **最大输入** | 960,000 Token。 | +| **最大输出** | 64,000 Token。 | +| **工具调用** | 通过函数调用连接外部工具,完成多步骤工作流。 | +| **结构化输出** | 支持结构化响应,用于信息提取和后续处理。 | +| **图像输入** | 支持 PNG、JPEG、WEBP 和静态 GIF;单张不超过 10 MB,每次请求最多 600 张(包含历史对话中的图像),同时受 Token 上限约束。 | + +### 已知限制 + +- 图像会在内部缩放至约 2048 × 2048 像素,超过 5500 × 5500 像素的输入会被拒绝;关注小字或精细内容时,建议先裁剪相关区域。 +- 执行代码、编辑文件或操作应用,需要运行环境具备相应外部工具和权限。 +- 使用思考保留的工具工作流,应在请求之间保留模型未经修改的思考历史,以获得更好的效果。 + +## 标准价格 + +以下 Token 价格均以美元计价,单位为每 100 万 Token;联网搜索按次计价。 + +| 模型 | 输入
(USD / 1M Tokens) | 缓存写入
(USD / 1M Tokens) | 缓存读取
(USD / 1M Tokens) | 输出
(USD / 1M Tokens) | 联网搜索
(USD / 次) | +| :--- | ---: | ---: | ---: | ---: | ---: | +| **Hy4 Flash** | `$0.07` | `$0.07` | `$0.003` | `$0.281` | - | + +**缓存写入:** B.AI 按输入价格的 1 倍计费。 + +**Credits 结算:** B.AI 按 `1 USD = 1,000,000 Credits` 换算费用,并从账户余额中扣除相应 Credits。 + +:::info 价格说明 +文档中的模型价格以模型提供方官方原价为基准,作为 B.AI 平台的标准参考价。平台可能在此基础上提供折扣或限时活动,相关优惠将在[活动与调整公告](../promotions-and-pricing-notices.md)及网站的折扣分组中展示。具体适用价格、优惠规则及最终费用,以平台页面展示和实际账单为准。 +::: diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/models/hy4.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/models/hy4.md index c2475fcc..706addc8 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/models/hy4.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/models/hy4.md @@ -16,10 +16,12 @@ Hy4 的 Token 计费项按标准参考价的 50% 结算,包括输入、输出 | 计费项 | 活动价格(USD / 1M Tokens) | | :--- | ---: | -| 输入 | `$0.42` | -| 缓存写入 | `$0.42` | -| 缓存读取 | `$0.02` | -| 输出 | `$1.25` | +| 输入 | `$0.4170` | +| 缓存写入 | `$0.4170` | +| 缓存读取 | `$0.0210` | +| 输出 | `$1.2505` | + +活动价格按对应官方原价的 50% 计算,统一保留四位小数。 下方标准价格表继续展示原价。活动信息详见[活动与调整公告](../promotions-and-pricing-notices.md),活动周期、实际结算价格及最终账单以平台页面展示为准。 diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/pricing-and-usage.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/pricing-and-usage.md index 6881b07a..14096ae2 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/pricing-and-usage.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/pricing-and-usage.md @@ -44,6 +44,7 @@ | Qwen3.7-Max | `$1.65` | `$1.65` | `$0.33` | `$4.951` | - | | Qwen3.7-Flash | `$0.03` | `$0.03` | `$0.006` | `$0.13` | - | | Qwen3.6-27B | `$0.19` | `$0.19` | `$0.019` | `$2.99` | - | +| Hy4 Flash | `$0.07` | `$0.07` | `$0.003` | `$0.281` | - | | Hy4 | `$0.834` | `$0.834` | `$0.042` | `$2.501` | - | | Hy4 Preview | `$0.834` | `$0.834` | `$0.042` | `$2.501` | - | | Hy3 | `$0.132` | `$0.132` | `$0.033` | `$0.528` | - | @@ -63,6 +64,8 @@ | DeepSeek V4 Pro | 空闲时段 `$0.66`
高峰时段 `$1.32` | 空闲时段 `$0.66`
高峰时段 `$1.32` | 空闲时段 `$0.022`
高峰时段 `$0.044` | 空闲时段 `$1.98`
高峰时段 `$3.96` | - | | Grok 4.6 | `$2.00` | `$2.00` | `$0.50` | `$6.00` | - | | Grok 4.5 | `$2.00` | `$2.00` | `$0.30` | `$6.00` | - | +| GPT-6.2 Astra | `$8.00` | 30 分钟:`$10.00`
12 小时:`$20.00` | `$0.40` | `$40.00` | `$0.01` | +| GPT-6.2 Sol | `$2.00` | 30 分钟:`$2.50`
12 小时:`$5.00` | `$0.10` | `$10.00` | `$0.01` | | GPT-6.1 Terra | `$1.00` | 30 分钟:`$1.25`
12 小时:`$2.50` | `$0.05` | `$5.00` | `$0.01` | | GPT-6.1 Sol | `$2.00` | 30 分钟:`$2.50`
12 小时:`$5.00` | `$0.10` | `$10.00` | `$0.01` | | GPT-6 Astra | `$10.00` | 30 分钟:`$12.50`
12 小时:`$25.00` | `$1.00` | `$50.00` | `$0.01` | @@ -115,7 +118,7 @@ **缓存价格:** “缓存写入(Cache Write)”表示发生缓存写入时的计费价格,不代表所有模型采用相同的缓存有效期。不同模型的缓存策略、有效期、长上下文价格和扩展缓存能力可能不同;如模型采用特殊缓存规则、1 小时缓存写入价格或分时价格,请查看对应模型详情页。 -**GPT 缓存写入时长:** GPT-5.6 Sol、Terra、Luna,GPT-6 Astra、Sol、Luna,以及 GPT-6.1 Sol、Terra 均区分 30 分钟和 12 小时缓存写入价格,分别为对应输入价格的 1.25 倍和 2.5 倍。写入价格替代对应 Token 的普通输入费用,不重复收取;两种时长的缓存读取价格相同。 +**GPT 缓存写入时长:** GPT-5.6 Sol、Terra、Luna,GPT-6 Astra、Sol、Luna,GPT-6.1 Sol、Terra,以及 GPT-6.2 Astra、Sol 均区分 30 分钟和 12 小时缓存写入价格,分别为对应输入价格的 1.25 倍和 2.5 倍。写入价格替代对应 Token 的普通输入费用,不重复收取;两种时长的缓存读取价格相同。 **长上下文分档:** 部分模型采用长上下文分档计价,总表展示基础档价格,具体门槛、完整价格及计费规则请查看对应模型详情页。 @@ -140,7 +143,7 @@ Auto 不是单独计费的模型。每次请求将按照实际执行的模型、 ### 缓存定价说明 -- **缓存写入(Cache Write):** 当 Token 首次写入 Prompt Cache 时产生的费用,单价取决于模型及缓存时长。上述 GPT-5.6、GPT-6 和 GPT-6.1 型号的 30 分钟写入为对应输入价的 1.25 倍,12 小时为 2.5 倍,均替代对应 Token 的普通输入费用。其他模型的写入价格与时长规则请查看对应详情页。 +- **缓存写入(Cache Write):** 当 Token 首次写入 Prompt Cache 时产生的费用,单价取决于模型及缓存时长。上述 GPT-5.6、GPT-6、GPT-6.1 和 GPT-6.2 型号的 30 分钟写入为对应输入价的 1.25 倍,12 小时为 2.5 倍,均替代对应 Token 的普通输入费用。其他模型的写入价格与时长规则请查看对应详情页。 - **缓存读取(Cache Read):** 后续请求复用缓存 token 时产生的折扣消耗。 - **缓存示例:** 如果你使用 Claude Sonnet 4.6,并有 1000 个 token 被缓存: - 首次请求(缓存写入):`1000 × 3.75 = 3,750 credits` diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/promotions-and-pricing-notices.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/promotions-and-pricing-notices.md index cc74c66e..4d65f372 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/promotions-and-pricing-notices.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/llmservice/promotions-and-pricing-notices.md @@ -10,6 +10,27 @@ import ActivityCard from '@site/src/components/ActivityCard'; 本栏目展示当前生效及已公布的近期活动:免费活动优先,折扣活动按优惠力度由高至低排列。 ::: + + +**优惠截止时间:2026 年 11 月 30 日 12:00(北京时间,UTC+8)。** + +活动期间,Hy4 Flash 的 Token 计费项按标准参考价的 50% 结算,包括输入、输出、缓存写入和缓存读取。本次活动仅适用于 `hy4-flash`。 + +| 计费项 | 活动价格(USD / 1M Tokens) | +| :--- | ---: | +| 输入 | `$0.035` | +| 缓存写入 | `$0.035` | +| 缓存读取 | `$0.0015` | +| 输出 | `$0.1405` | + +优惠结束后恢复按标准参考价结算。[定价与用量](./pricing-and-usage.md)价格总表和[模型详情](./models/hy4-flash.md)继续展示原价。具体适用规则及最终费用,以平台页面展示和实际账单为准。 + + @@ -32,11 +55,17 @@ Hy4 的 Token 计费项按标准参考价的 50% 结算,包括输入、输出 variant="discount" title="DeepSeek-V4.1-Flash" status="限时折扣" - detail="10 月 4 日 10:00 SGT 起 6 折" + detail="5 折" > -活动于 2026 年 10 月 4 日 10:00(SGT,新加坡时间,UTC+8)起生效。 -自生效时间起,活动价格随 DeepSeek 空闲时段与高峰时段同步变化,各时段均按对应标准价的 60% 结算。 +活动期间,输入、输出、缓存写入和缓存读取均按对应空闲时段或高峰时段标准参考价的 50% 结算,活动价格随 DeepSeek 峰谷计价同步变化。 + +以下活动价格均以美元计价,单位为每 100 万 Token。 + +| 计费时段 | 输入 | 缓存写入 | 缓存读取 | 输出 | +| :--- | ---: | ---: | ---: | ---: | +| 空闲时段 | `$0.075` | `$0.075` | `$0.0015` | `$0.30` | +| 高峰时段 | `$0.15` | `$0.15` | `$0.003` | `$0.60` | [定价与用量](./pricing-and-usage.md)价格总表和[模型详情](./models/deepseek-v4-1-flash.md)继续展示标准参考价,实际结算价格及最终账单以平台页面展示为准。 diff --git a/package.json b/package.json index 6f168579..d565282d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@x402-tron/docs", - "version": "1.5.6", + "version": "1.5.7", "description": "x402-tron documentation", "license": "MIT", "resolutions": { @@ -11,6 +11,7 @@ "**/@typescript-eslint/typescript-estree/minimatch": "11.0.7" }, "scripts": { + "postinstall": "node scripts/patch-picomatch.mjs", "docusaurus": "docusaurus", "start": "docusaurus start", "start-zh": "docusaurus start --locale zh-Hans", diff --git a/scripts/audit-dependencies.mjs b/scripts/audit-dependencies.mjs new file mode 100644 index 00000000..3b96ca00 --- /dev/null +++ b/scripts/audit-dependencies.mjs @@ -0,0 +1,57 @@ +import { spawnSync } from 'node:child_process' +import { verifyPicomatchPatches } from './patch-picomatch.mjs' + +const verifiedVersions = verifyPicomatchPatches() +const audit = spawnSync('yarn', ['audit', '--json', '--non-interactive', '--network-timeout', '60000'], { + encoding: 'utf8', + maxBuffer: 16 * 1024 * 1024, + stdio: ['ignore', 'pipe', 'inherit'], +}) +if (audit.error) throw audit.error + +const severityFlags = { info: 1, low: 2, moderate: 4, high: 8, critical: 16 } +const counts = { info: 0, low: 0, moderate: 0, high: 0, critical: 0 } +let summary +let failed = false +let covered = 0 + +for (const line of audit.stdout.split('\n').filter(Boolean)) { + const { type, data } = JSON.parse(line) + if (type === 'warning' || type === 'error') console.error(data) + if (type === 'error') failed = true + if (type === 'auditSummary') { + if (summary) throw new Error('Yarn returned more than one audit summary') + summary = data + } + if (type !== 'auditAdvisory') continue + + const { advisory, resolution } = data + if (!Object.hasOwn(counts, advisory.severity)) throw new Error('Unknown audit severity') + counts[advisory.severity]++ + + // Yarn sees the registry versions even after the verified local backport. + if (advisory.id === 1247710 && resolution.id === advisory.id && + advisory.module_name === 'picomatch' && advisory.severity === 'high' && + advisory.github_advisory_id === 'GHSA-fc5q-39xc-vjpf' && + advisory.cves?.length === 1 && advisory.cves[0] === 'CVE-2026-112366' && + advisory.findings?.length && advisory.findings.every(({ version }) => verifiedVersions.has(version))) { + covered++ + continue + } + + console.error(`${advisory.severity}: ${advisory.module_name} — ${advisory.url} (${resolution.path})`) + failed = true +} + +let expectedStatus = 0 +for (const [severity, flag] of Object.entries(severityFlags)) { + if (summary?.vulnerabilities?.[severity] !== counts[severity]) { + throw new Error(`Incomplete Yarn audit results for severity ${severity}`) + } + if (counts[severity]) expectedStatus |= flag +} +if (audit.status !== expectedStatus) throw new Error(`Unexpected Yarn audit exit status ${audit.status}`) + +if (covered) console.log(`Verified backport covers ${covered} findings for GHSA-fc5q-39xc-vjpf`) +console.log(`Yarn audited ${summary.totalDependencies} packages`) +if (failed) process.exitCode = 1 diff --git a/scripts/check-nginx-scan.mjs b/scripts/check-nginx-scan.mjs new file mode 100644 index 00000000..f952adf7 --- /dev/null +++ b/scripts/check-nginx-scan.mjs @@ -0,0 +1,14 @@ +import {readFileSync} from 'node:fs' + +const versionOutput = process.argv[2] ?? '' +const version = /^nginx version: nginx\/(\d+\.\d+\.\d+)$/.exec(versionOutput)?.[1] +if (!version) throw new Error(`Unexpected nginx -v output: ${versionOutput}`) + +const report = JSON.parse(readFileSync(0, 'utf8')) +const purl = `pkg:generic/nginx@${version}` +const cpes = ['f5', 'nginx'].map(vendor => `cpe:2.3:a:${vendor}:nginx:${version}:*:*:*:*:*:*:*`) +const identified = report.components?.some(component => + component.purl === purl && component.version === version && cpes.includes(component.cpe), +) +if (!identified) throw new Error(`Grype did not identify upstream Nginx ${version} in its scan report`) +console.log(`[security] Grype identified ${purl} with its upstream CPE`) diff --git a/scripts/nginx-scan.test.mjs b/scripts/nginx-scan.test.mjs new file mode 100644 index 00000000..ee25caad --- /dev/null +++ b/scripts/nginx-scan.test.mjs @@ -0,0 +1,39 @@ +import assert from 'node:assert/strict' +import {spawnSync} from 'node:child_process' +import test from 'node:test' +import {fileURLToPath} from 'node:url' + +const script = fileURLToPath(new URL('./check-nginx-scan.mjs', import.meta.url)) +const component = { + version: '1.2.3', + purl: 'pkg:generic/nginx@1.2.3', + cpe: 'cpe:2.3:a:f5:nginx:1.2.3:*:*:*:*:*:*:*', +} + +function verify(components, versionOutput = 'nginx version: nginx/1.2.3') { + return spawnSync(process.execPath, [script, versionOutput], { + input: JSON.stringify({bomFormat: 'CycloneDX', components}), + encoding: 'utf8', + }) +} + +test('accepts an upstream Nginx component matching the running server', () => { + for (const vendor of ['f5', 'nginx']) { + const result = verify([{...component, cpe: `cpe:2.3:a:${vendor}:nginx:1.2.3:*:*:*:*:*:*:*`}]) + assert.equal(result.status, 0, result.stderr) + } +}) + +test('rejects an empty catalog, a version mismatch and missing upstream identifiers', () => { + for (const result of [ + verify([]), + verify(undefined), + verify([component], 'nginx version: nginx/1.2.4'), + verify([{...component, version: '1.2.4'}]), + verify([{...component, purl: 'pkg:apk/alpine/nginx@1.2.3-r0'}]), + verify([{...component, cpe: undefined}]), + verify([component], ''), + ]) { + assert.equal(result.status, 1, result.stderr) + } +}) diff --git a/scripts/patch-picomatch.mjs b/scripts/patch-picomatch.mjs new file mode 100644 index 00000000..bf33ef9e --- /dev/null +++ b/scripts/patch-picomatch.mjs @@ -0,0 +1,117 @@ +import { createHash, randomUUID } from 'node:crypto' +import { globSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs' +import { dirname, join } from 'node:path' +import { fileURLToPath } from 'node:url' + +// Remove this backport after both locked versions have upstream replacements. +const parserHashes = new Map([ + ['2.3.2', { + original: '3a91656f440069aa8f8e15c9d695b9f6b2209df1eab2be8127c72cbcca45ff5f', + patched: '6eeeeed5fba1a469c6dd921f79faa29c35caff71bdbc634f5bbd43e5eb123b18', + }], + ['4.0.7', { + original: '4e1e05447668aa1e94366c5516a2bcd8f5fff800cc92b1d0cd7d77703b8618c4', + patched: '0a9aaf24f515602c0472e816c90164f103f390e1700be415dfced9855cd10abc', + }], +]) +const originalClose = ` const extglobClose = token => { + const literal = input.slice(token.startIndex, state.index + 1); + const body = input.slice(token.startIndex + 2, state.index); + const analysis = analyzeRepeatedExtglob(body, opts); + + if ((token.type === 'plus' || token.type === 'star') && analysis.risky) {` +const patchedClose = String.raw` const hasRegexStar = source => { + let inClass = false; + for (let i = 0; i < source.length; i++) { + const ch = source[i]; + if (ch === '\\') { + if (++i === source.length) return true; + } else if (ch === '[') { + inClass = true; + } else if (ch === ']') { + inClass = false; + } else if (ch === '*' && !inClass) { + return true; + } + } + return inClass; + }; + + const repeatedBodyHasStar = token => { + const open = tokens[token.tokensIndex]; + const paren = tokens[token.tokensIndex + 1]; + if (!open || !paren || !paren.extglob) return true; + + const start = token.output.length; + const opening = open.output + paren.output; + if (!state.output.startsWith(opening, start)) return true; + if (hasRegexStar(state.output.slice(start + opening.length))) return true; + + // A later token can make the parser rebuild its output from these tokens. + const rebuilt = tokens.slice(token.tokensIndex + 2) + .map(part => (part.output ?? part.value) + (part.suffix ?? '')) + .join(''); + return hasRegexStar(rebuilt); + }; + + const extglobClose = token => { + const literal = input.slice(token.startIndex, state.index + 1); + const body = input.slice(token.startIndex + 2, state.index); + const analysis = analyzeRepeatedExtglob(body, opts); + const repeated = token.type === 'plus' || token.type === 'star'; + // CVE-2026-112366: inspect the emitted regex so literal stars stay literal. + const nestedStar = repeated && !analysis.risky && body.includes('*') + && splitTopLevel(body).length === 1 && repeatedBodyHasStar(token); + + if (repeated && (analysis.risky || nestedStar)) {` +const originalFallback = ' open.output = safeOutput || utils.escapeRegex(literal);' +const patchedFallback = String.raw` open.output = safeOutput || literal.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&');` + +function sha256(content) { + return createHash('sha256').update(content).digest('hex') +} + +export function verifyPicomatchPatches({ apply = false } = {}) { + const root = fileURLToPath(new URL('../', import.meta.url)) + const manifests = globSync([ + 'node_modules/picomatch/package.json', + 'node_modules/**/node_modules/picomatch/package.json', + ], { cwd: root }) + const verified = new Set() + + for (const manifest of manifests) { + const { version } = JSON.parse(readFileSync(join(root, manifest), 'utf8')) + const hashes = parserHashes.get(version) + if (!hashes) continue + + const path = join(root, dirname(manifest), 'lib/parse.js') + const source = readFileSync(path, 'utf8') + const hash = sha256(source) + if (hash !== hashes.patched) { + if (!apply || hash !== hashes.original) { + throw new Error(`Expected the validated picomatch ${version} parser at ${path}`) + } + + const patched = source.replace(originalClose, () => patchedClose).replace(originalFallback, () => patchedFallback) + if (sha256(patched) !== hashes.patched) { + throw new Error(`Picomatch ${version} backport produced unexpected content`) + } + + const temporary = `${path}.${randomUUID()}.tmp` + try { + writeFileSync(temporary, patched, { flag: 'wx' }) + renameSync(temporary, path) + } finally { + rmSync(temporary, { force: true }) + } + } + verified.add(version) + } + + return verified +} + +if (import.meta.main) { + const versions = verifyPicomatchPatches({ apply: true }) + if (versions.size) console.log(`Verified picomatch backport for ${[...versions].sort().join(', ')}`) +} diff --git a/scripts/picomatch.test.mjs b/scripts/picomatch.test.mjs new file mode 100644 index 00000000..8d7dea3c --- /dev/null +++ b/scripts/picomatch.test.mjs @@ -0,0 +1,50 @@ +import assert from 'node:assert/strict' +import { createRequire } from 'node:module' +import test from 'node:test' + +const require = createRequire(import.meta.url) + +for (const consumer of ['micromatch', 'tinyglobby']) { + const requireFromConsumer = createRequire(require.resolve(consumer)) + const picomatch = requireFromConsumer('picomatch') + const { version } = requireFromConsumer('picomatch/package.json') + + test(`picomatch ${version} preserves escaped stars in repeated extglobs`, () => { + assert.equal(picomatch.makeRe(String.raw`+(docs\*)`).test('docs*docs*'), true) + assert.equal(picomatch.makeRe(String.raw`*(docs\*)`).test('docs*'), true) + assert.equal(picomatch.makeRe(String.raw`+(docs\\\*)`).test(String.raw`docs\*`), true) + }) + + test(`picomatch ${version} preserves literal stars in parsed groups`, () => { + const cases = [ + ['+(docs[*])', 'docs*'], + ['*(docs[*])', 'docs*docs*'], + ['+(docs[0*])', 'docs0docs*'], + ['+(docs[[:digit:]*])', 'docs0docs*'], + ['+(docs{1..3}[*])', 'docs2*'], + ['+("*")', '*'], + ] + + for (const [pattern, input] of cases) { + assert.equal(picomatch.makeRe(pattern).test(input), true, pattern) + } + }) + + test(`picomatch ${version} still guards repeated wildcard stars`, () => { + const cases = [ + [String.raw`+(docs\*notes*)`, { flags: 'u' }], + [String.raw`+(docs\\*)`], + [String.raw`+(docs\*)`, { unescape: true }], + ['+(docs[*]notes*)'], + ['+(docs[*])', { nobracket: true }], + ['+(docs*)', { maxExtglobRecursion: false }], + ] + + for (const [pattern, options] of cases) { + const [, opening] = picomatch.parse(pattern, options).tokens + assert.equal(opening.type, 'text', pattern) + assert.equal(opening.value, pattern) + assert.equal(picomatch.makeRe(pattern, options).test(pattern), true, pattern) + } + }) +} diff --git a/scripts/prepare-nginx-runtime.sh b/scripts/prepare-nginx-runtime.sh index 3fdc2316..001f768b 100644 --- a/scripts/prepare-nginx-runtime.sh +++ b/scripts/prepare-nginx-runtime.sh @@ -5,15 +5,11 @@ runtime_root=/runtime mkdir -p "$runtime_root/etc/apk" cp -a /etc/apk/keys "$runtime_root/etc/apk/" cp /etc/apk/repositories "$runtime_root/etc/apk/repositories" +cp /tmp/nginx-package/*.rsa.pub "$runtime_root/etc/apk/keys/" -# Install only ELF dependencies, without maintainer scripts or a shell. -# APK retains the real inventory for every installed library. -runtime_deps=$(scanelf --needed --nobanner --format '%n#p' /usr/sbin/nginx | tr ',' '\n' | sed 's/^/so:/') -test -n "$runtime_deps" -# Intentional splitting: each line is a separate shared-library dependency. -# shellcheck disable=SC2086 +# Install the exact signed package and its shared libraries into the final root. apk --root "$runtime_root" --initdb --no-cache --no-scripts add \ - alpine-release $runtime_deps + alpine-release /tmp/nginx-package/nginx-*.apk # Nginx currently needs no Brotli decoder. If that changes, keep the previous # CVE-2026-111497 version floor rather than introducing a vulnerable library. @@ -21,44 +17,29 @@ if apk --root "$runtime_root" info --exists brotli-libs; then apk --root "$runtime_root" --no-cache --no-scripts add 'brotli-libs>=1.2.1-r0' fi -mkdir -p "$runtime_root/usr/sbin" "$runtime_root/etc/nginx/conf.d" \ +mkdir -p "$runtime_root/etc/nginx/conf.d" \ "$runtime_root/etc/nginx/snippets" "$runtime_root/usr/share/nginx/html" \ "$runtime_root/app/logs" "$runtime_root/run" "$runtime_root/var/log/nginx" \ "$runtime_root/var/cache/nginx" "$runtime_root/tmp" -cp /usr/sbin/nginx "$runtime_root/usr/sbin/nginx" -cp /etc/nginx/mime.types "$runtime_root/etc/nginx/mime.types" cp /etc/passwd /etc/group "$runtime_root/etc/" chmod 1777 "$runtime_root/tmp" chown -R nginx:nginx "$runtime_root/app/logs" "$runtime_root/var/log/nginx" "$runtime_root/var/cache/nginx" -for license_dir in /usr/share/licenses/nginx /usr/share/doc/nginx; do - if [ -d "$license_dir" ]; then - mkdir -p "$runtime_root$(dirname "$license_dir")" - cp -a "$license_dir" "$runtime_root$license_dir" - fi -done - -# Nginx is copied from the official upstream image, rather than installed with its -# /bin/sh maintainer-script dependency. Preserve its original APK inventory so -# the runtime vulnerability scan still includes Nginx itself. -source_db=/lib/apk/db/installed -runtime_db="$runtime_root/lib/apk/db/installed" -if [ ! -f "$source_db" ]; then source_db=/usr/lib/apk/db/installed; fi -if [ ! -f "$runtime_db" ]; then runtime_db="$runtime_root/usr/lib/apk/db/installed"; fi -nginx_record=$(awk 'BEGIN { RS="" } /(^|\n)P:nginx(\n|$)/ { print }' "$source_db") -test -n "$nginx_record" -printf '\n%s\n\n' "$nginx_record" >> "$runtime_db" - for package in nginx musl; do apk --root "$runtime_root" info --exists "$package" done -for package in busybox busybox-binsh ssl_client; do +for package in busybox busybox-binsh ssl_client libssl3 libcrypto3; do if apk --root "$runtime_root" info --exists "$package"; then echo "Unexpected runtime package: $package" >&2 exit 1 fi done +openssl_files=$(find "$runtime_root" \( -name 'libssl.so*' -o -name 'libcrypto.so*' \) -print) +if [ -n "$openssl_files" ]; then + printf 'Unexpected OpenSSL runtime library:\n%s\n' "$openssl_files" >&2 + exit 1 +fi test ! -e "$runtime_root/bin/busybox" test ! -e "$runtime_root/bin/sh" test ! -e "$runtime_root/sbin/apk" diff --git a/sidebars.js b/sidebars.js index 7b97f84e..ab8897bd 100644 --- a/sidebars.js +++ b/sidebars.js @@ -154,6 +154,8 @@ const sidebars = { label: 'OpenAI (GPT)', collapsed: true, items: [ + { type: 'doc', id: 'llmservice/models/gpt-6-2-astra', label: 'GPT-6.2 Astra' }, + { type: 'doc', id: 'llmservice/models/gpt-6-2-sol', label: 'GPT-6.2 Sol' }, { type: 'doc', id: 'llmservice/models/gpt-6-1-terra', label: 'GPT-6.1 Terra' }, { type: 'doc', id: 'llmservice/models/gpt-6-1-sol', label: 'GPT-6.1 Sol' }, { type: 'doc', id: 'llmservice/models/gpt-6-astra', label: 'GPT-6 Astra' }, @@ -236,6 +238,7 @@ const sidebars = { label: 'Tencent Hunyuan (Hy)', collapsed: true, items: [ + { type: 'doc', id: 'llmservice/models/hy4-flash', label: 'Hy4 Flash' }, { type: 'doc', id: 'llmservice/models/hy4', label: 'Hy4' }, { type: 'doc', id: 'llmservice/models/hy4-preview', label: 'Hy4 Preview' }, { type: 'doc', id: 'llmservice/models/hy3', label: 'Hy3' }, @@ -392,6 +395,7 @@ const sidebars = { collapsed: true, items: [ { type: 'doc', id: 'llmservice/api/API', label: 'API Overview' }, + { type: 'doc', id: 'llmservice/api/minimax-image-generation', label: 'MiniMax Image Generation API' }, { type: 'doc', id: 'llmservice/api/videos', label: 'Video Generation API' }, { type: 'doc', id: 'llmservice/api/decisions-api', label: 'Decisions API' }, { type: 'doc', id: 'llmservice/api/balance', label: 'Balance API' },