Skip to content

Repository files navigation

ms2api

OpenAI-compatible Aistudio adapter.

Currently supported:

  • POST /v1/chat/completions
  • POST /v1/files
  • GET /v1/models

License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0-only).

If you modify this project and make it available to users over a network, you must also make the corresponding source code of your modified version available under the same license terms.

Account management

The runtime now uses managed accounts only.

  • The server also auto-loads a local .env file when present
  • Set MS2API_ADMIN_PASSWORD before starting the server
  • Open the admin panel at /
  • Add account credentials there
  • Trigger login and enter the email verification code
  • Export / import the managed account library as JSON when needed
  • Only enabled managed accounts participate in request routing

Legacy cookie directories are kept only as login artifacts and are no longer auto-discovered for request handling.

Example .env:

MS2API_ADMIN_PASSWORD=change-me
MS2API_ADMIN_SESSION_SECRET=replace-this-too

You can also start the container with --env-file .env, and the app will still read the same variables at runtime.

File support

The adapter now supports forwarding attachments to Aistudio.

Recommended flow:

  1. Upload a file to POST /v1/files
  2. Put the returned file_id into the last user message
  3. Send POST /v1/chat/completions

Example message payload:

{
  "model": "mimo-v2-flash",
  "messages": [
    {
      "role": "user",
      "content": [
        { "type": "text", "text": "请总结附件内容" },
        { "type": "input_file", "file_id": "file_xxx" }
      ]
    }
  ]
}

Also supported:

  • inline input_file.file_data via data: URL
  • inline image_url.url via data: URL

For security, remote http(s) attachment URLs are currently rejected.

Model IDs

GET /v1/models exposes Aistudio model name as the OpenAI-compatible id.

Examples:

  • mimo-v2-flash
  • mimo-v2-pro
  • mimo-v2-omni

The adapter will map those public names back to the real upstream backend model identifiers automatically.

Search-enabled model variants

For chat models that support web search, the adapter also exposes a -search variant in GET /v1/models.

Examples:

  • mimo-v2-flash → search disabled
  • mimo-v2-flash-search → search enabled
  • mimo-v2-pro → search disabled
  • mimo-v2-pro-search → search enabled

Current behavior:

  • The -search suffix automatically sets upstream modelConfig.webSearchStatus = "enabled"
  • The plain model ID keeps search disabled
  • If the request contains attachments, search is still forced to disabled
  • Omni models do not currently expose a -search variant

GET /v1/models also includes:

  • web_search_enabled
  • parent

Docker

The repository now includes a production Dockerfile.

Build locally:

docker build -t ms2api:local .

Run locally:

docker run --rm -p 8000:8000 \
  --env-file .env \
  -v "$(pwd)/data:/data" \
  ms2api:local

Container defaults:

  • listens on 0.0.0.0:8000
  • stores runtime data in /data
  • keeps these paths persistent inside the mounted volume:
    • /data/accounts.json
    • /data/aistudio-http-login
    • /data/openai-files
    • /data/logs

If you do not use --env-file, at minimum you should provide:

-e MS2API_ADMIN_PASSWORD=change-me

GitHub Container Registry automation

The repository now includes .github/workflows/docker.yml.

Behavior:

  • triggers on every push
  • can also be run manually with workflow_dispatch
  • builds the Docker image from Dockerfile
  • pushes it to GitHub Container Registry (ghcr.io)

The published image name is based on the repository path:

ghcr.io/<owner>/<repo>

Common tags produced by the workflow:

  • branch name
  • sha-<commit>
  • latest on the default branch

Example pull:

docker pull ghcr.io/<owner>/<repo>:latest

Notes:

  • GitHub links the package to the repository automatically when it is first published from this workflow using GITHUB_TOKEN
  • The first published package is private by default on GHCR
  • If the same GHCR package namespace was pushed manually before and was not connected to this repository, the workflow may not have permission to push until you connect or clean up that package in GitHub

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages