feat(ai): support configurable request JSON library#13386
Open
nic-6443 wants to merge 41 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an APISIX-level setting apisix.request_body_json_lib (default qjson, options cjson/simdjson/qjson) controlling the JSON library used by core.request.get_request_body_table and by AI transport upstream body encoding. Introduces a new module apisix.core.request_json that lazily loads the selected library, plus rockspec dependencies on lua-qjson and lua-resty-simdjson.
Changes:
- New module
apisix/core/request_json.luaselecting between cjson/qjson/simdjson based on local config, wired intoapisix/core/request.luaand AI transport encoders (ai-transport/http.lua,ai-transport/auth-aws.lua). - Schema + default config additions for
request_body_json_lib, and new rockspec depslua-qjsonandlua-resty-simdjson. - Docs (en/zh) and tests covering selector behavior, AI encoder routing, and the new default in
config-default.t.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| apisix/core/request_json.lua | New selector module with lazy load of qjson/simdjson and cjson fallback. |
| apisix/core/request.lua | Replaces core.json.decode with request_json.decode for request body parsing. |
| apisix/plugins/ai-transport/http.lua | Switches upstream body encode to request_json.encode. |
| apisix/plugins/ai-transport/auth-aws.lua | Switches SigV4 body encode to request_json.encode; drops unused core import. |
| apisix/cli/schema.lua | Adds enum schema for request_body_json_lib. |
| apisix/cli/config.lua | Adds default request_body_json_lib = "qjson". |
| conf/config.yaml.example | Documents new option in example config. |
| apisix-master-0.rockspec | Adds lua-qjson and lua-resty-simdjson dependencies. |
| docs/en/latest/plugins/ai-proxy.md | English docs for the new option. |
| docs/zh/latest/plugins/ai-proxy.md | Chinese docs for the new option. |
| t/core/request.t | Adds tests for selector behavior and AI transport encoder routing. |
| t/core/config-default.t | Adds assertion on the new default value. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bzp2010
reviewed
May 19, 2026
AlinsRan
previously approved these changes
May 20, 2026
shreemaan-abhishek
previously approved these changes
May 20, 2026
membphis
previously approved these changes
May 20, 2026
8219798
AlinsRan
approved these changes
May 20, 2026
shreemaan-abhishek
approved these changes
May 20, 2026
moonming
reviewed
May 20, 2026
| git \ | ||
| openldap-dev \ | ||
| pcre-dev \ | ||
| rust \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds an APISIX-level JSON library selector for request body parsing used by core.request.get_request_body_table, and reuses the same selector for AI upstream request body encoding.
The supported values are cjson, simdjson, and qjson. The default is simdjson. qjson is available as an experimental option for users who explicitly opt in after evaluating compatibility. The config schema owns the enum/default validation, and request_json caches the validated value from local_conf. The selected decode/encode behavior is fixed by the configured value: cjson uses cjson decode and encode, simdjson uses simdjson decode and cjson encode, and qjson uses qjson decode and encode. qjson decode results are materialized before returning from core.request so existing table consumers such as JSONPath matching can keep using normal Lua table traversal.
lua-qjson and api7-lua-resty-simdjson are installed through LuaRocks dependencies. The simdjson package keeps cjson array metadata for decoded arrays, so empty arrays still round-trip as arrays when encoded by cjson. The Rust toolchain bootstrap logic is shared by CI and install-dependencies to keep the minimum rustc/rustup setup in one place. Docker build paths that run make deps also install or carry the Rust/helper prerequisites needed to build simdjson.
Docs include benchmark data for cjson, simdjson, and qjson on large AI request bodies.
Tests added/updated:
Checks run: