A method and system for secure API call control based on dynamic permission policies

By acquiring call status data for dynamic authentication, forming permission status tokens and generating permission constraint instructions, the problems of permission solidification and resource loss control in large-scale API calls are solved, and the accuracy and real-time performance of permission control are improved.

CN123122977APending Publication Date: 2026-11-17SHANGHAI ZHONGYANG BIG DATA TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202611478162.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-22
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

Existing large-scale API call control systems struggle to dynamically adjust permission boundaries based on call status, leading to issues such as rigid permissions, unauthorized calls, and resource out-of-control problems.

Method used

Dynamic authentication is performed by acquiring call status data, forming a permission status token. Based on the permission status token, request adjudication and permission constraint instructions are executed to generate controlled API requests and update call status data to trigger dynamic authentication iteration.

Benefits of technology

It significantly improves the accuracy and real-time performance of access control for large model API calls, responds promptly to changes in models, interfaces, and resource consumption, avoids continuously using the initial access control range, and enhances access control and security control capabilities during continuous calls to large model APIs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123122977A_ABST
    Figure CN123122977A_ABST
Patent Text Reader

Abstract

This invention discloses a method and system for secure API call control based on dynamic permission policies, relating to the field of communication access control technology. The method includes the following steps: acquiring call status data and performing dynamic authentication to form a permission status token; executing request adjudication based on the permission status token to generate permission constraint instructions; obtaining controlled API requests by implementing permission convergence on the permission constraint instructions; and implementing call status backtracking based on the controlled API requests, updating the call status data, and triggering dynamic authentication iteration. This application solves the problem of unauthorized access and resource loss caused by static solidification of API call permissions in large-model systems through dynamic backtracking of call trajectories and continuous iteration of permission boundaries.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of communication access control technology, and more specifically, to a method and system for controlling secure API calls based on dynamic permission policies. Background Technology

[0002] As large-scale models and intelligent agents are increasingly used in enterprise business systems, model services are gradually completing multi-stage calls through APIs, tool interfaces, and external service nodes. This places higher demands on the dynamism of API access control, the granularity of permission boundaries, and continuous security verification during the call process. NIST recently pointed out in its analysis of AI agent identity and authorization that dynamic authorization, least privilege, and permission updates during runtime are crucial issues for AI agent security control. Therefore, how to generate a continuously updated permission state based on the actual call state, transmit dynamic authentication results to the API request execution process, and simultaneously adjust subsequent permission boundaries based on changes in the call trajectory has become a pressing technical problem to be solved in the field of large-scale model API secure call control. For example, the invention patent with publication number CN121508935A discloses a method and system for large model access authentication and traffic control based on an APISIX gateway. This invention relates to the field of artificial intelligence technology, specifically a method and system for large model access authentication and traffic control based on an APISIX gateway, including the following steps: the client generates an HTTPS request containing an APIKey and sends it to the APISIX gateway cluster; the gateway extracts the APIKey and forwards it to the authentication service to verify the validity of the key; after successful verification, the authentication service returns a user permission matrix, and the gateway verifies whether the request is within the permission range; after successful permission verification, the traffic control plugin detects traffic indicators according to a preset policy; when the traffic indicators are within limits, the gateway forwards the request to the large model service and returns the result; when the traffic indicators exceed limits, the gateway performs rate limiting / circuit breaking and returns the corresponding error response. The beneficial effects are: the gateway performs request forwarding or rate limiting control based on preset policies, effectively solving the problems of illegal access risks and resource allocation imbalances faced by large model services, improving service stability and resource utilization efficiency, and is suitable for the security operation and maintenance of large model services in multiple scenarios.

[0003] For example, the invention patent with publication number CN121071908A discloses an API execution method, apparatus, and storage medium with dynamic permission control. This disclosure relates to an API execution method, apparatus, and storage medium with dynamic permission control. The API execution method includes: receiving an API request sent by a user and performing permission verification on the API request; assessing the risk of the API request in response to the permission verification failing; issuing dynamic temporary permission in response to the risk assessment result meeting a threshold; and completing the API request based on the dynamic temporary permission.

[0004] The above-disclosed technical solutions have at least the following technical problems: Existing large-scale API call control systems struggle to dynamically adjust permission boundaries based on call status, leading to issues such as rigid permissions, unauthorized calls, and resource out-of-control problems.

[0005] To address the above problems, this invention proposes a solution. Summary of the Invention

[0006] To overcome the aforementioned deficiencies of the prior art, embodiments of the present invention provide a method and system for controlling secure API calls based on dynamic permission policies. By dynamically tracing the call trajectory and continuously iterating the permission boundaries, the method solves the problems of unauthorized access and resource out-of-control caused by static solidification of API call permissions.

[0007] To achieve the above objectives, the present invention provides the following technical solution: A method for controlling secure API calls based on dynamic permission policies includes: acquiring call status data and performing dynamic authentication to form a permission status token; executing request adjudication based on the permission status token to generate permission constraint instructions; obtaining controlled API requests by implementing permission convergence on the permission constraint instructions; and implementing call status backtracking based on the controlled API requests, updating the call status data, and triggering dynamic authentication iteration.

[0008] In a preferred technical solution, the process of obtaining call status data and performing dynamic authentication to form a permission status token is as follows: Obtain call status data and perform call subject parsing to determine the current call subject status; based on the current call subject status, obtain model access permissions, interface access permissions, and token quota status, and perform permission boundary reorganization to form subject permission boundaries; receive a large model API request initiated by the current call subject, parse the request credential, target model, and target interface, and perform request subject binding to obtain the current request status; obtain the real-time usage status of the current subject through the current request status, and perform usage status aggregation to determine the current call status; based on the current... The system dynamically prunes permissions based on the subject's permission boundaries and shrinks the permission scope to determine real-time permission boundaries. Based on these real-time permission boundaries, it performs dynamic authentication on the current request status and determines request-level permissions, generating a request authorization scope. Based on this authorization scope, it binds permissions to the API key, the calling subject, and the request identifier, limiting the current API call chain and forming a call permission binding status. The system analyzes the permission validity period, allowed model range, and allowed interface range through the call permission binding status and assembles the permission status to form a token payload. Finally, it securely binds the token payload to the calling subject identifier, request identifier, and API key and issues the token, forming a permission status token.

[0009] In a preferred technical solution, the step of dynamically pruning permissions based on the current call state and shrinking the permission range to determine the real-time permission boundary is as follows: A hierarchical occupancy chain of employee quotas, department quotas, and API key quotas is established based on the current call state to form a quota occupancy sequence; the API requests currently being executed by the employee and their department are identified through the quota occupancy sequence, and concurrent occupancy intervals are divided to form real-time occupancy intervals; the available quota range corresponding to the current API request is determined based on the real-time occupancy interval, and the current request Token occupancy state is placed into the available quota range to form a request available quota range; the model access range in the subject permission boundary is traversed according to the request available quota range, and permissions are shrunk to form a model interface permission chain; the target model and target interface of the current request are determined based on the model interface permission chain, and the executable call range of the current request is shrunk to form a request real-time permission range; the current API key, calling subject, and request identifier are limited to the model, interface, and Token quota through the request real-time permission range, and the limited state is attached to the current API call request to form a request permission constraint state; permission range is transferred based on the request permission constraint state to form the real-time permission boundary.

[0010] In a preferred technical solution, the step of executing request adjudication based on permission status tokens and generating permission constraint instructions specifically includes: extracting the calling entity identifier, API key identifier, and request identifier based on the permission status token, locating the request context, establishing a request index for the token, and forming a token request location node; reading the permission version, key status version, and permission validity period based on the token request location node, dividing the token's available time period, and mapping the permission version and key status version to the time period to obtain a token validity slice; parsing the target model and target interface based on the token validity slice, locating the model service route and locating the interface processing path, and generating a request access path; obtaining employee permissions, department permissions, API key permissions, and token permissions based on the request access path, and performing hierarchical intersection processing on the model access scope to form a model. Intersection permissions; based on the intersection permissions of the models, the access scope of the interfaces is obtained, and the quota pre-occupancy analysis is performed to form the request quota pre-occupancy status; based on the request quota pre-occupancy status, the quota gap of the current request is identified, and the model interface combination that meets the remaining quota is obtained for substitution matching to generate the request model interface adjustment status; based on the request model interface adjustment status, the final target model, target interface and token quota are determined, and the model routing, interface path and quota limit are organized to obtain the request execution path; based on the request execution path, the model routing node, interface processing node and token quota limit are extracted respectively, and organized into various fields to form a constraint instruction field set; based on the constraint instruction field set, the execution entry point is determined, and each field is passed to the model routing service and model call adaptation layer in sequence, and the instructions are encapsulated to form permission constraint instructions.

[0011] In a preferred technical solution, the step of obtaining the interface access range based on model intersection permissions and performing quota pre-occupancy analysis to form a request quota pre-occupancy status is as follows: Based on model intersection permissions, determine the model interface combination and divide the token consumption items to form request token measurement items; based on the request token measurement items, aggregate the token demand of the current request, add the interface consumption to form a token demand range, and limit the demand range to form request token demand segments; map the request token demand segments sequentially and divide them into occupiable intervals to form a multi-level quota mapping chain; associate concurrent requests based on the multi-level quota mapping chain, and... The quota occupancy order is arranged, and the quota that is about to be released is included in the available range to form a concurrent quota occupancy sequence. Based on the concurrent quota occupancy sequence, the request token demand segment is shrunk, and the part exceeding any quota boundary is truncated, retaining the token range that can be carried by each level of quota to form a request pre-occupied quota segment. Based on the request pre-occupied quota segment, the hierarchical quota atomic occupancy is performed, and the request identifier and occupied amount are written to the quota occupancy record, and the remaining quota at each level is updated synchronously to form a request quota pre-occupancy record. Based on the request quota pre-occupancy record, the quota occupancy results at each level are aggregated, and the model interface and pre-occupied token amount are associated to form a request quota pre-occupancy status.

[0012] In a preferred technical solution, the controlled API request is obtained by implementing permission convergence through permission constraint instructions, specifically as follows: The model route, interface access, token limit, and permission period are parsed using permission constraint instructions, and each constraint item is sorted to establish a request constraint processing sequence; Model route replacement is implemented according to the request constraint processing sequence, and call content that cannot enter the restricted service node is removed, resulting in a model-restricted request; Interface path rewriting is implemented based on the model-restricted request, and the interface address and call direction in the original request are replaced to form an interface-restricted request; Quota phase division is implemented according to the interface-restricted request to generate a phase quota control segment; Request content compression is implemented through the phase quota control segment, the current request content is segmented, and content exceeding the quota is gathered to form reconstructed request content; Request data replacement is implemented based on the reconstructed request content, and the call content in the original request is overwritten to generate a phase-restricted request; Execution chain progression is implemented according to the phase-restricted request, and expired execution data is truncated to form a time-restricted execution chain; Execution data is solidified through the time-restricted execution chain to form a permission convergence context; Request structure reconstruction is implemented based on the permission convergence context, and the original request identifier is retained to generate a controlled API request.

[0013] In a preferred technical solution, the step of compressing the request content through a phased quota control segment, segmenting the current request content, and converging content exceeding the quota to form reconstructed request content, is specifically as follows: Content segmentation is performed based on the phased quota control segment, content boundaries are defined, and tokens are used to measure each content segment, marking the token usage to obtain a set of request content segments; quota mapping is performed based on the request content segment set, the available token quota for the phase is written into the content segments, and the difference between the token usage and the available quota is calculated to obtain a phased quota allocation table; content converging is performed on the phased quota allocation table to obtain a phased converging content set; structural compression is performed based on the phased converging content set. Adjacent messages are merged, duplicate content is converged, and content length is adjusted to obtain the stage-reconstructed content. Based on the stage-reconstructed content, a request for reorganization is implemented, and the token usage after reorganization is remeasured to obtain the actual token usage result. By implementing quota feedback on the actual token usage result, the difference between the actual token usage and the available quota for the stage is calculated, the content segment causing the quota deviation is located, and the available quota for subsequent stages is updated. Boundary convergence and structural compression are then performed on the content segment again to obtain the dynamic reconstructed content. Based on the dynamic reconstructed content, a request for write-back is implemented, synchronously updating the message index, role field, tool data, and token usage marker to obtain the reconstructed request content.

[0014] In a preferred technical solution, the step of implementing call state backtracking based on controlled API requests, updating call state data, and triggering dynamic authentication iteration specifically includes: solidifying the execution permission context based on controlled API requests and synchronously transmitting it with model and tool calls to establish a permission context mapping; reconstructing the call chain based on the permission context mapping to obtain an execution state chain; marking the execution state chain and associating the actual model, interface, and token consumption of each state with the execution node to obtain an actual execution state set; and comparing the execution permission difference based on the actual execution state set to locate the deviation between actual execution and permission constraints, thus obtaining a permission execution deviation set. The system performs state updates based on the permission deviation set, updating the model and interface states to obtain updated call state data. It then performs version control on the updated call state data and merges versions of concurrently generated state changes to obtain a consistent call state. Based on the consistent call state, it performs permission change judgment, identifying state changes that meet dynamic authentication conditions and obtaining authentication iteration markers. Based on these authentication iteration markers, it performs permission state iteration and regenerates permission state tokens to obtain iterated permission states. Finally, based on the iterated permission states, it re-executes permission decisions, passing the updated model routes, interface access scope, token amount, and permission duration to subsequent request processing flows.

[0015] In a preferred technical solution, the step of comparing the execution permission difference based on the actual execution state set to locate the deviation between the actual execution and the permission constraints, and obtaining a permission execution deviation set, specifically involves: reconstructing the actual call order of the current request based on the actual execution state set, associating it with permission constraints, and establishing a permission execution baseline trajectory; mapping the actual execution nodes to the permission execution baseline trajectory, rearranging the actual call sequence, and associating model, interface, and tool call branches to obtain the actual call trajectory; performing node matching between the actual call trajectory and the permission execution baseline trajectory, and calculating the trajectory offset to obtain the permission trajectory deviation set; and matching the permission trajectory deviation set with the node's token. Resource consumption is correlated with resource consumption, retry count, and execution duration to calculate changes in resource consumption, identify continuously increasing resource consumption branches, and obtain a resource consumption trend set. Based on the permission trajectory deviation set and the resource consumption trend set, a correlation judgment is made to determine the direction of subsequent permission contraction, maintenance, or expansion, generating a dynamic permission boundary. Based on the dynamic permission boundary, the token amount, model, and interface access range of subsequent execution nodes are adjusted. Calls exceeding the boundary are subject to limits, switching, or termination processing to obtain the permission execution status. The permission execution status is then compared again with the actual call trajectory, correlated with trajectory offset and resource consumption changes, and the actual deviations are collected to form a permission execution deviation set.

[0016] A system for controlling secure API calls based on dynamic permission policies includes a dynamic authentication module, a request adjudication module, a permission convergence module, and a state backtracking module. These modules are interconnected: the dynamic authentication module acquires call state data and performs dynamic authentication to generate a permission state token; the request adjudication module executes request adjudication based on the permission state token, generating permission constraint instructions; the permission convergence module converges permissions through the permission constraint instructions to obtain controlled API requests; and the state backtracking module performs call state backtracking based on the controlled API requests, updates the call state data, and triggers dynamic authentication iterations.

[0017] The technical effects and advantages of this invention, which describes a method and system for controlling secure API calls based on dynamic permission policies, are as follows: 1. This invention obtains call status data and performs dynamic authentication in conjunction with the current request context to form a permission status token carrying permission status. Then, it executes request adjudication and generates permission constraint instructions based on the permission status token. This can associate the current call status with the permission scope of the specific API request, so that the model, interface and call resources have clear permission constraints before the request is executed, which significantly improves the accuracy and real-time performance of API call permission control for large models.

[0018] 2. This invention forms controlled API requests by implementing permission convergence on permission constraint instructions, and backtracks the call state after the request is executed. The actual execution result is used to update the call state data and trigger dynamic authentication iteration. This enables the subsequent permission state to be continuously adjusted with the actual call process, responding in a timely manner to changes in models, interfaces and resource consumption, avoiding the continuous use of the initial permission range, and significantly improving the permission adaptation and security control capabilities during continuous API calls of large models. Attached Figure Description

[0019] Figure 1 This is a flowchart illustrating a large-scale API security call control method based on dynamic permission policies according to the present invention.

[0020] Figure 2 This is a schematic diagram of the system architecture of a large-scale API security call control method based on dynamic permission policy according to the present invention. Technical solution

[0021] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.

[0022] Example 1, Figure 1 This invention presents a method for controlling secure API calls in a large model based on dynamic permission policies, comprising the following steps: S1, obtain the call status data, perform dynamic authentication, and generate an authorization status token; In this embodiment, the call status data is obtained and dynamic authentication is performed to form a permission status token, as detailed below: Obtain the call status data, combine the employee identity status, department permission status, and API key usage status to perform call subject parsing, and determine the current call subject status. The call status data includes employee identity data, department permission data, API key status data, model permission data, and token usage data. The current call subject status is used to characterize the employee identity, department, API key ownership, and API key usage status corresponding to the current large model API request. Based on the current calling entity status, obtain the model access permission, interface access permission, and Token quota status. Combine the hierarchical restrictions of department quota and employee quota to perform permission boundary reorganization and form the entity permission boundary. The entity permission boundary is used to characterize the model access range, interface access range, and calling quota range formed by the current calling entity under the constraints of its department permissions, employee permissions, and Token quota. Receive the large model API request initiated by the current calling entity, parse the request credentials, target model and target interface, perform request entity binding in combination with the API key ownership relationship, and obtain the current request status. The current request status is used to represent the request credentials, API key, calling entity, target model, target interface and request identifier corresponding to the current large model API request. The system obtains the real-time usage status of the current entity based on the current request status. It then aggregates the usage status by combining the used tokens, remaining quotas, and the current request usage to determine the current call status. Specifically, it determines the corresponding API key, employee, and department based on the current request status. It then reads the API call records of the large model, employee quota records, and department quota records according to the correspondence between the API key, employee, and department to form the entity's historical usage status. Based on the entity's historical usage status, it obtains the used tokens and remaining quotas corresponding to the API key, employee, and department. It then combines these with the target model and target interface corresponding to the current request to determine the token usage status of the current request. It merges the token usage status of the current request with the entity's historical usage status to form the entity's current usage status. Based on the entity's current usage status, it identifies other API requests under the same employee and department that are in the process of being called and updates the entity's current usage status according to the token usage status corresponding to each API request to form the entity's concurrent usage status. Based on the entity's concurrent usage status, it determines the real-time available quota corresponding to the current employee quota and department quota. Finally, it combines the real-time available quota with the token usage status corresponding to the current request to form the current call status. Based on the current call status, dynamic permission pruning is performed on the subject permission boundary. Permission range is shrunk according to the target model permissions, target interface permissions and current quota status to determine the real-time permission boundary. Dynamic authentication is performed on the current request status based on the real-time permission boundary. Request-level permission determination is implemented according to the calling subject, target model, target interface, and real-time quota, generating the request authorization scope. Specifically, this involves: obtaining the model access scope, interface access scope, and call quota range from the real-time permission boundary; determining the request subject, target model, and target interface from the current request status; performing consistency matching between the request subject and the calling subject in the real-time permission boundary to determine the subject authorization status corresponding to the current request; determining the permission scope of the target model based on the subject authorization status; and matching the target model with the allowed models in the model access scope item by item to determine the model corresponding to the current request. The authorization status is determined by analyzing the target interface's scope based on the model's authorization status. The target interface is matched item by item with the allowed interfaces in the access scope to determine the authorization status of the interface corresponding to the current request. Based on the interface authorization status, the real-time available quota in the current call status is read, and the available call quota for this request is determined according to the token occupancy status of the target model and the target interface. The available call quota for this request is constrained with the real-time available quota to determine the quota authorization status of the current request. The main authorization status, model authorization status, interface authorization status, and quota authorization status are combined according to the current request status to form the request authorization scope corresponding to the current request. Based on the scope of the authorization request, permissions are bound to the API key, the calling subject, and the request identifier. The current API call chain is limited according to the authorization scope to form a call permission binding state. Specifically, the following steps are taken: the subject authorization state, model authorization state, interface authorization state, and quota authorization state in the scope of the authorization request are obtained. The API key, calling subject, and request identifier are determined from the current request state. According to the relationship between the subject authorization state and the API key, the model authorization state, interface authorization state, and quota authorization state are bound to the corresponding API key to form a key authorization state. The calling subject corresponding to the current API key is determined according to the key authorization state, and the subject authorization state is bound to the current calling subject to form a subject permission state. The model authorization state, interface authorization state, and quota authorization state are bound to the current request identifier according to the subject permission state to form a request permission state. The target model, target interface, and token call quota corresponding to the current request identifier are limited according to the request permission state. The request permission state is continuously attached to the call request of the corresponding API key according to the current API call chain to form a call permission binding state. By analyzing the permission binding status, the validity period of permissions, the scope of allowed models, and the scope of allowed interfaces, and combining the current call status, permission status is assembled to form a token payload. The token payload is used to represent the binding relationship between the API key and the calling subject in the current API call chain, the target model and target interface corresponding to the request identifier, and the available token amount and permission validity period corresponding to the current call status. It is organized into permission control content that can be read by the API gateway according to the preset token fields. The token payload is securely bound to the caller identifier, request identifier, and API key. Token issuance is performed according to the current API call chain to form an authorization status token. The authorization status token is used to represent the caller, API key, request identifier, model and interface permissions, token amount, and authorization validity period corresponding to the current API call, and serves as an authorization credential for the API gateway to implement dynamic call control.

[0023] In this embodiment, dynamic permission pruning is performed on the subject permission boundary based on the current call state. The permission range is shrunk according to the target model permissions, target interface permissions, and the current quota state to determine the real-time permission boundary, as follows: Based on the current call status, a hierarchical occupancy chain of employee quotas, department quotas, and API key quotas is established, and a quota occupancy sequence is formed according to the token occupancy order of the current API request and concurrent API requests. The quota occupancy sequence is used to represent the token occupancy order formed by API key, employee, and department, and records the corresponding request identifier, target model, and target interface. The system identifies the API requests currently being executed by employees and their departments based on the quota occupancy sequence. Concurrent occupancy intervals are then defined according to the model, interface, and token occupancy status of each API request, forming real-time occupancy intervals. Specifically, this involves: obtaining the request identifier, employee identifier, and department identifier from the quota occupancy sequence; filtering API requests in the queuing, sending, and model response processes according to their processing status to form the current concurrent request set; reading the target model, target interface, and token occupancy status of each API request based on the current concurrent request set; summarizing the token occupancy status of each API request according to the employee identifier and department identifier to form employee concurrent occupancy status and department concurrent occupancy status; determining the start and end status of each API request's occupancy at the corresponding quota level based on the employee concurrent occupancy status and department concurrent occupancy status; arranging the occupancy positions of each request according to the API request's entry time and token occupancy status to form concurrent occupancy intervals; identifying the quota overlap between the current API request and other API requests based on the concurrent occupancy intervals; and grouping API requests with overlapping quotas into the same real-time occupancy interval to form real-time occupancy intervals. The available quota range corresponding to the current API request is determined based on the real-time occupancy interval, and the current request token occupancy status is placed into the available quota range to form the request available quota range. Specifically, the remaining available quota of the current employee quota and department quota is obtained based on the real-time occupancy interval, and the previous occupancy quota is determined according to the occupancy position of the current API request in the real-time occupancy interval. The quota range that the current request can enter is determined based on the quota boundary between the previous occupancy quota and the corresponding remaining available quota. The token occupancy status of the current request is placed into the corresponding quota range according to the target model and target interface. The available quota range that the current request can simultaneously satisfy the employee and department quotas is determined by combining the hierarchical constraints of the employee quota and department quota. The executable quota range of the request is divided according to the overlap between the token occupancy status of the current request and the available quota range to form the request available quota range. Based on the available quota range, the system iterates through the model access range within the main permission boundary and shrinks the permissions according to the interface access range and Token usage restrictions corresponding to each model, forming a model interface permission chain. Specifically, the system obtains the model access range and the interface access range corresponding to each model within the main permission boundary. It groups the allowed calling models and corresponding interfaces according to the model identifier to form a model interface candidate group. It reads the Token usage restrictions corresponding to each model based on the available quota range and matches the Token usage restrictions of each model with the available quota range group by group to determine the model interface candidate group that meets the current available quota. It continues to filter available interfaces according to the interface access range corresponding to the target model and shrinks the quota range of available interfaces according to the Token usage restrictions corresponding to the available interfaces to form a model interface constraint group. It obtains the models, interfaces and corresponding available Token quotas in the model interface constraint group and determines the corresponding model interface constraint relationship according to the target model and target interface of the current API request. It organizes the model interface constraint relationship continuously according to the model access level, interface access level and quota restrictions within the main permission boundary to form a model interface permission chain. Based on the model interface permission chain, the target model and target interface corresponding to the current request are determined, and the executable call range of the current request is narrowed according to the constraint relationship between the target model, target interface and the available quota range of the request, forming the real-time permission range of the request. The real-time permission range of the request is used to characterize the actual call range that the current API request is allowed to execute under the constraints of the target model, target interface and the available quota of the token. By requesting real-time permission scope, the current API key, calling subject, and request identifier are limited to the corresponding model, interface, and token amount, and the limitation state is attached to the current API call request to form a request permission constraint state. The request permission constraint state is used to represent the real-time limitation relationship between the API key, calling subject, and request identifier corresponding to the current API request and the target model, target interface, and token amount that are allowed to be called. Based on the request permission constraint state, permission scope is transferred along the request transmission link from the API gateway to the model service to form a real-time permission boundary. The real-time permission boundary is used to characterize the target model, target interface, and token amount range that are actually allowed to be accessed during the process of the current API request being transmitted from the API gateway to the model service.

[0024] S2, execute request adjudication based on permission status token, and generate permission constraint instructions; In this embodiment, the request is adjudicated based on the permission status token, and a permission constraint instruction is generated, as follows: Based on the permission status token, the calling entity identifier, API key identifier, and request identifier are extracted. The request context of the current API request in the gateway is located according to the request identifier. The request index corresponding to the token is established to form a token request location node. The token request location node is used to represent the current API request location information corresponding to the permission status token. The token request locates the node to read the permission version, key status version, and permission validity period. The token's available time period is divided based on the current request time. The permission version and key status version are mapped to the corresponding time period to obtain the token validity slice. The token validity slice is used to represent the permission version, key status version, and validity period applicable to the current permission status token within the corresponding time period. Based on token time-limited slicing, the target model and target interface in the current API request are parsed, and the model service route is located according to the model identifier, and the interface processing path is located according to the interface identifier to generate the request access path. The request access path is used to represent the route entry, interface processing node and call direction corresponding to the current API request entering the target model service from the API gateway. Based on the requested access path, employee permissions, department permissions, API key permissions, and token permissions are obtained. Then, a hierarchical intersection processing is performed on the model access scope corresponding to each permission to form model intersection permissions. Specifically, this involves: obtaining the employee identifier, department identifier, API key identifier, and token identifier corresponding to the requested access path; and reading the employee model authorization table, department model authorization table, API key model authorization table, and token model authorization table based on each identifier, extracting the model identifiers within the current permission's validity period from each authorization table, forming employee model sets, department model sets, key model sets, and token model sets, respectively. An initial intersection filter is performed based on the model identifiers of the employee model set and the department model set, retaining models commonly allowed to be called by the employee's department, forming the department-employee model set. Finally, based on the API key identifier, the models allowed to be called by the current API key are extracted from the key model set. The model is then intersected with the department employee model set to form a key-constrained model set. The model authorization range corresponding to the current token is determined based on the token validity slice. The token authorization range is then intersected with the key-constrained model set to filter out models that cannot be called by the current token, forming a final model set. The model version, calling region, and service node corresponding to each model in the final model set are obtained, and node mapping is performed according to the model service route in the request access path. Models that cannot match the current calling path are removed from the final model set, forming a model callable set. Continuous model access items are generated according to the model identifiers in the model callable set, and the corresponding permission source and validity period are attached to each model access item to form a model intersection permission. The model intersection permission is used to represent the callable model set jointly limited by employees, departments, API keys, and permission status tokens. Based on the intersection of the model permissions, the access range of the corresponding interface is obtained, and the quota pre-occupancy analysis is performed by combining the estimated Token usage of the current request with the real-time available quota to form the quota pre-occupancy status of the request. The system identifies the current request's quota gap based on the quota pre-allocation status and retrieves model interface combinations that satisfy the remaining quota from the model intersection permissions. It then performs substitution matching based on token consumption levels to generate a request model interface adjustment status. Specifically, this involves: obtaining the current request's token demand and remaining available quota from the quota pre-allocation status; calculating the current request's quota gap; determining the required reduction range of token consumption based on the gap; extracting the models and corresponding interfaces accessible to the current caller from the model intersection permissions based on the required reduction range; and adjusting the token consumption based on the model's unit token consumption and the interface's corresponding token usage cap. Sort the model interfaces to form a candidate sequence. Based on the candidate sequence, filter out model interface combinations whose token consumption exceeds the remaining available quota. Match the target model with the candidate models according to their functional types and interface capabilities. Retain the candidate combinations that can handle the current request. Select the candidate combinations in order of token consumption from low to high. The first model interface combination that meets the remaining quota and has the corresponding interface capability is determined as the alternative call combination. Write the model identifier, interface identifier and corresponding token quota of the alternative call combination into the current request. Retain the original target model and target interface as the call record before the request adjustment to form the request model interface adjustment status. Based on the request model interface adjustment state, the final target model, target interface, and token limit of the current request are determined. The model routing, interface path, and limit limit are organized according to the actual call order from the final model to the interface to obtain the request execution path. The request execution path is used to represent the actual forwarding order of the current API request after the permission adjudication, from the API gateway to the model routing service, interface processing node, and finally to the target model execution node. Based on the request execution path, extract the model routing node, interface processing node, and token limit, and organize each constraint into model routing field, interface access field, and token control field. Combine the permission validity period to form a constraint instruction field set. The constraint instruction field set is used to represent the model routing node, interface processing node, token limit, and permission validity period corresponding to the current API request in the actual forwarding process. Based on the constraint instruction field set, the execution entry point of the current API request in the API gateway is determined. The model routing field, interface access field, and token control field are then sequentially passed to the model routing service and the model invocation adaptation layer. Instructions are encapsulated based on the request identifier and permission validity period to form permission constraint instructions. Specifically: the gateway entry point corresponding to the current API request is determined according to the constraint instruction field set; the current request context is read according to the request identifier; the model routing field, interface access field, and token control field are extracted from the request context; these fields are arranged according to their order of action in the request execution path to form a request constraint data sequence; the model routing field is written into the routing control data of the current request, the interface access field is written into the interface control data of the current request, and the token control field is written into the limit control data of the current request, forming a request constraint data group; and the request constraint data group is then passed along the request execution path to… The model routing service reads model routing control data and determines the corresponding target model service node. It then passes the determined target model service node and interface control data to the interface processing node. Based on the interface processing node's read interface control data, it determines the corresponding target call interface and passes it to the model call adaptation layer along with quota control data. The model call adaptation layer reads quota control data to determine the allowed token quota for the current request. It combines the model service node, target call interface, and token quota according to the actual call order of the current request and associates them with the request identifier and permission validity period to form a request constraint execution chain. Based on this chain, it uniformly encapsulates the model, interface, and token control content corresponding to each node to generate a permission constraint instruction for the current API request. This permission constraint instruction represents the target model, target interface, token quota, and validity period corresponding to the current API request and serves as unified control data for each call node to enforce permission restrictions.

[0025] In this embodiment, the access scope of the corresponding interface is obtained based on the intersection of the model permissions, and quota pre-allocation analysis is performed by combining the estimated Token usage of the current request with the real-time available quota to form the request quota pre-allocation status, as follows: Based on the model intersection permissions, the model interface combination of the current request is determined, and the token consumption items are divided according to the input, output and interface consumption to form the request token meter item. The request token meter item is used to represent the meter details of the input token consumption, output token consumption and interface fixed token consumption generated by the current API request during the corresponding model interface call process. The token requirement of the current request is collected based on the request token metering item, and the interface consumption is added to form the token requirement range. The requirement range is limited according to the usage boundary corresponding to the model interface to form the request token requirement segment. The request token requirement segment is used to represent the expected token amount range that the current API request will need to occupy in this model interface call, as well as the available upper limit boundary corresponding to the amount range. The request token demand segment is mapped sequentially along the quota levels of employees, departments, and API keys, and the available quota range is divided according to the remaining quota at each level to form a multi-level quota mapping chain. Specifically, the request token demand segment is associated with the employee identifier corresponding to the current request and mapped to the employee's remaining quota. The request token demand segment is first divided according to the employee's remaining quota to obtain the employee's available quota range. The employee's available quota range is associated with the corresponding department identifier and mapped to the department's remaining quota. The employee's available quota range is then divided a second time according to the department's remaining quota to obtain the department's available quota range. The department's available quota range is associated with the API key identifier and mapped to the API key's remaining quota. The department's available quota range is then divided a third time according to the API key's remaining quota to obtain the key's available quota range. The employee's available quota range, the department's available quota range, and the key's available quota range are then linked together according to the hierarchical mapping relationship. The quota boundaries and remaining quotas corresponding to each level of the range are recorded to form a multi-level quota mapping chain. The multi-level quota mapping chain is used to subsequently determine the common available quota range of the current request under the three-level quota of employees, departments, and API keys. Based on a multi-level quota mapping chain, concurrent requests at corresponding levels are associated. Quota occupancy is ordered according to the occupied quota and expected release time, and quotas nearing release are included in the available range, forming a concurrent quota occupancy sequence. Specifically: the quota mapping positions for employee, department, and API key quota levels are determined according to the multi-level quota mapping chain; concurrent requests are associated with each quota mapping position; the current occupied token quota and expected release time of each concurrent request are obtained; the concurrent requests are sorted according to the expected release time to form the quota occupancy order for each quota level; and the already released quota and the quota awaiting release are identified based on the quota occupancy order. The quota is directly merged into the remaining quota of the corresponding quota level. Based on the quota difference between the current request token demand segment and the remaining quota of each level, it is determined whether the quota to be released can supplement the available quota of the current request. The quota to be released that can supplement the current request quota is marked as a temporary available quota. The temporary available quota is merged with the remaining quota of the corresponding level to obtain the updated available quota range of each level. The updated available quota range of each level is sequentially associated according to the quota level of employees, departments and API keys. The quota occupied by concurrent requests at each level, the release order and the updated available quota are linked together according to the quota level to form a concurrent quota occupancy sequence. Based on the concurrent quota occupancy sequence, the request token demand segment is shrunk along the quota level, and the part exceeding any quota boundary is truncated, retaining the token range that can be carried by each quota level, forming a request pre-occupied quota segment. Specifically, the available quota ranges after the update of the three quota levels of employees, departments and API keys are obtained according to the concurrent quota occupancy sequence. The request token demand segment is then overlapped and matched with the available quota range of each level in the order of employee, department and API key. The part of the request token demand segment that exceeds the employee's available quota range is truncated to obtain the employee's token range. The employee's token range is then overlapped and matched with the department's available quota range, and the part that exceeds the department's available quota is truncated to obtain the department's token range. The department's token range is then overlapped and matched with the API key's available quota range, and the part that exceeds the API key's available quota is truncated to obtain the key's token range. The key's token range is then used as the token quota range that can be carried by all three quota levels. It is associated with the current request identifier and the corresponding model interface to form a request pre-occupied quota segment. Based on the requested pre-occupied quota segment, the hierarchical quota atomic occupancy is performed, and the request identifier and occupied quota are written into the corresponding quota occupancy record. The remaining quota at each level is updated synchronously to form the request quota pre-occupancy record. The request quota pre-occupancy record is used to represent the actual pre-occupied quota, corresponding occupancy relationship and pre-occupancy status of the current API request in each quota level of employee, department and API key. Based on the requested quota pre-allocation record, the quota occupancy results at each level are aggregated, and the model interface and pre-allocated Token quota of the current request are associated. The pre-allocation time and quota range are written into the quota status data to form the requested quota pre-allocation status. The requested quota pre-allocation status is used to characterize the pre-allocation results and current valid status of the current API request's model interface and Token quota at each quota level of employee, department, and API key.

[0026] S3 obtains controlled API requests by implementing permission convergence on permission constraint instructions; In this embodiment, controlled API requests are obtained by implementing permission convergence on the permission constraint instructions, as detailed below: The system parses model routing, interface access, token quota, and permission expiration by using permission constraint instructions. It sorts each constraint item according to the execution order of API requests to establish a request constraint processing sequence. The request constraint processing sequence is used to represent the execution order in which the API gateway applies model routing restrictions, interface path adjustments, token quota control, and permission expiration processing to the current request in sequence, and records the processing position and subsequent execution nodes corresponding to each constraint item. Based on the request constraint processing sequence, model routing replacement is implemented. The target model in the original API request is redirected to the limited service node, and the call content that cannot enter the limited service node is removed, resulting in a model-restricted request. The model-restricted request is used to represent the request data status of the current API request after model routing is converged, including the restricted target model, the corresponding service node, and the retained model call content. Based on the model-restricted request, the interface path is rewritten, the interface call path is adjusted to the processing position corresponding to the restricted service node, and the interface address and call direction in the original request are replaced to form an interface-restricted request. The interface-restricted request is used to represent the executable data status of the current API request after the interface call path reconstruction is completed, including the target interface path, request method and interface call parameters. Based on the restricted API request, the token quota is divided into stages and allocated along the request processing process to the input processing, model generation and result output stages. A stage quota control segment is generated. The quota stage division is based on the token measurement item of the current API request, the pre-occupied token quota and the token usage boundary of the target model interface. The stage quota control segment is used to characterize the available token quota and its boundary range corresponding to each processing stage of the current API request, and record the range of request content that each stage can bear. The request content is compressed by implementing a phased quota control segment. The current request content is divided according to the available quota of each phase, and the content that exceeds the corresponding quota is gathered to form the reconstructed request content. Based on the refactoring request content, request data replacement is performed. The refactored content is written to the corresponding model and interface processing nodes, overwriting the call content in the original request, and generating a stage-restricted request. Specifically, this involves: obtaining the original request fields corresponding to the refactoring request content; determining the target write position of the refactoring content according to the model service node and interface processing node; extracting the corresponding model parameters, message parameters, and interface parameters from the original request to form request field location results; writing the retained content segments in the refactoring request content to the corresponding message parameters and request parameters according to the field positions based on the request field location results; and rearranging the written fields according to the current data organization order of the model interface to form the request data to be replaced. Take the quota boundary corresponding to the quota control segment of the stage, determine the message fragments and input fragments that exceed the quota range of the current stage along the located request fields, delete the excess content from the request data to be replaced, and adjust the field length, parameter index and Token control parameters after the deletion to form stage update request data. Update the corresponding fields in the original request based on the stage update request data, replace the original model call content with the stage update request data, and write the updated model service node, interface processing node and request content into the execution context of the current API request. Switch the reading position of the request field according to the reading order of the subsequent processing nodes so that the subsequent model call directly reads the replaced request data to form a stage-restricted request. The execution chain is progressively executed based on the stage-restricted request. The model, interface, and request content generated in the current stage are passed to subsequent processing stages, and expired execution data is truncated according to the permission period, forming a time-restricted execution chain. Specifically, the model service node, interface processing node, and request data corresponding to the next processing stage are determined based on the stage-restricted request. The model node, interface path, and reconstruction request content from the stage-restricted request are written into the execution parameters of the next processing stage according to the actual call order. The request data output by the current stage is used as the input data for the next stage, forming progressive execution data. The corresponding data for each subsequent processing stage is obtained based on the progressive execution data. The execution time point is matched with the validity period of the permissions in the permission constraint instruction. The subsequent execution data that exceeds the validity period of the permissions is intercepted according to the order of model call, interface processing and result generation. The execution data within the validity period continues to be passed to the corresponding processing node. At the same time, the writing of request content to the processing node that exceeds the validity period is stopped, forming time-limited truncated data. Based on the time-limited truncated data, the subsequent execution order of the current request is reorganized. The model node, interface node and request content that have not exceeded the validity period of the permissions are sequentially linked together. The truncated subsequent nodes are removed from the execution sequence to form a time-limited execution chain. By implementing execution data solidification through a time-constrained execution chain, the model, interface, quota, and request content after each stage's convergence are written into subsequent execution data, overwriting the corresponding original execution data to form a permission convergence context. Specifically, this involves: obtaining the model service node, interface processing node, token quota, and request content retained in the current request based on the time-constrained execution chain; extracting the corresponding execution data according to the order of each node in the execution chain; and writing each execution data into the execution context position corresponding to the current request to form a stage execution dataset; determining the corresponding request fields based on the model nodes and interface nodes in the stage execution dataset; and writing the time-constrained request content and token quota into the relevant fields. The corresponding fields are updated according to the node order of the current execution chain, forming updated execution data. Based on the updated execution data, the corresponding execution fields in the original execution context are located, and the model nodes, interface paths, quota parameters and request content in the original fields are replaced with the updated execution data. The input positions and field indices of the subsequent nodes are adjusted synchronously to form execution data coverage results. According to the execution data coverage results, the execution parameters of the subsequent processing nodes are updated sequentially along the time-limited execution chain. The execution data after the current node completes the convergence is passed to the next node and overwrites the original execution data of the next node until the continuous writing of the corresponding nodes of the time-limited execution chain is completed, forming the permission convergence context. Based on the permission convergence context, the request structure is reconstructed. The converged model node, interface path, request content, token amount, and permission period are combined into new execution data, while retaining the original request identifier. A controlled API request is generated. The controlled API request is used to represent the executable request data after the reconstruction of the model node, interface path, request content, token amount, and permission period. The fields are combined according to the data format of the target interface and can be directly entered into the subsequent gateway forwarding process.

[0027] In this embodiment, request content compression is implemented through a phased quota control segment. The current request content is segmented according to the available quota for each phase, and content exceeding the corresponding quota is gathered to form reconstructed request content, as detailed below: Based on the phase quota control segment, the content is segmented, the content boundary is divided according to the Token quota of each processing stage, and the Token is measured for each content segment. The corresponding Token usage is marked to obtain the request content segment set. The request content segment set is used to represent the request content segments divided by processing stage and marked with Token usage and their corresponding field positions. Based on the requested content segment set, the quota mapping is implemented, the available Token quota for each stage is written into the corresponding content segment, the difference between the Token usage and the available quota is calculated, and the stage quota allocation table is obtained. The stage quota allocation table is used to represent the correspondence between the available Token quota, actual usage and remaining quota for each content segment. By performing content convergence on the phase quota allocation table, the excess content segments are located according to the quota difference, and the excess part is truncated along the corresponding quota boundary, while the non-excess content is retained, to obtain the phase convergence content set. The phase convergence content set is used to represent the request content segments retained after being truncated by the Token quota boundary and their corresponding remaining quota information. Structural compression is implemented based on the phased convergence content set. Adjacent messages are merged, duplicate content is converged, and the content length is adjusted according to the remaining quota. Simultaneously, the association between system instructions, current input, and tool call fields is maintained to obtain the phased reconstructed content. Specifically: Each content segment and its corresponding remaining quota in the phased convergence content set are obtained. The compressible range is determined according to the remaining quota, and each content segment undergoes field scanning to identify adjacent historical messages, duplicate messages, and mergeable message segments, resulting in compressible content segments. Based on the field positions and message types of the compressible content segments, adjacent historical messages of the same type are continuously merged, and the token usage after merging is recalculated to obtain the message merged segment. The message merging segment identifies duplicate content and redundant content referenced by subsequent messages. Redundant content is truncated, retaining content still involved in the current request processing to obtain a content truncated segment. This content truncated segment is matched with the corresponding remaining quota. Historical messages exceeding the length are truncated according to the remaining quota, while maintaining the integrity of system instructions, current inputs, and tool call fields to obtain a length-limited content segment. The message index, role field, and tool data association position are adjusted according to the message changes in the length-limited content segment to obtain structure-related content. Token measurement is re-executed on the structure-related content, and the measurement result is compared with the remaining quota of the corresponding stage. For content still exceeding the quota, length truncation is performed again to obtain the stage reconstructed content. Based on the phased reconstruction content, a request reorganization is implemented, writing the reconstruction content back to the corresponding request fields, synchronously adjusting the message index, role field, and tool data positions, and re-measuring the reorganized Token usage to obtain the actual Token usage result. Specifically, this involves: obtaining the message fields and corresponding field positions in the phased reconstruction content; determining the writing positions of message, role, and tool data according to the original request data structure; writing the phased reconstruction content sequentially into the corresponding request fields and rearranging each field according to the message processing order to obtain the request reorganization data; readjusting the message index based on the number of messages and field changes in the request reorganization data; rebinding the merged or consolidated messages with the corresponding role fields and synchronously updating the association position between tool call parameters and corresponding messages to obtain the field association request; reorganizing the request body based on the field association request; combining the message parameters, tool data, and other request parameters required by the model interface according to the data format of the target interface to obtain the reorganization request; performing Token measurement based on the reorganization request; calculating the Token usage for each reorganized message field and tool data; and writing the measurement results into each processing phase to obtain the actual Token usage result. By implementing quota feedback on the actual token usage results, the difference between the actual token usage and the available quota for each stage is calculated. This identifies the content segments causing quota deviations, updates the available quota for subsequent stages based on the difference, and performs boundary contraction and structural compression on the content segments again to obtain dynamically reconstructed content. Specifically: The actual token usage for each processing stage is obtained from the actual token usage results; the corresponding available quota is extracted according to the stage quota allocation table; the quota difference between the actual usage and the available quota is calculated; the content segments whose actual usage exceeds the stage quota are located based on the quota difference, resulting in quota deviation segments; the change in available quota for subsequent processing stages is determined based on the quota deviation segments; and the excess portion is adjusted accordingly. The corresponding quota is deducted from the subsequent available quota, and the unused quota is passed to the next stage to obtain the updated stage quota. Based on the updated stage quota, the content processing boundary of the quota deviation segment is re-determined. The message content that exceeds the updated quota is truncated, and the adjacent messages and duplicate content after truncation are merged and converged again to obtain the secondary compressed content. Based on the secondary compressed content, the message index, role field and tool data association relationship are readjusted, and the token measurement is re-executed. The re-measurement result is compared with the updated stage quota. For content that still exceeds the quota, the boundary adjustment is continued until the actual token usage of each processing stage does not exceed the corresponding available quota, and the dynamically reconstructed content is obtained. Based on the dynamic reconstruction content, a request write-back is implemented. The content is recombined according to the updated field structure, and the message index, role field, tool data and token occupancy flag are updated synchronously to obtain the reconstruction request content. The reconstruction request content is used to represent the executable request data formed after token quota convergence and dynamic adjustment.

[0028] S4, Implement call status backtracking based on controlled API requests, update call status data, and trigger dynamic authentication iteration; In this embodiment, the call status is traced back according to the controlled API request, the call status data is updated, and dynamic authentication iteration is triggered, as follows: Based on the controlled API request execution permission context solidification, the permission status, constraint status and execution version corresponding to the current request are written into the call context and synchronously transmitted with the model and tool calls, establishing a permission context mapping corresponding to each execution node. The permission context mapping is used to represent the correspondence between the permission status, permission constraints and execution version and each execution node, and records the permission scope and context version corresponding to each node. The call chain is reconstructed based on the permission context mapping. Model calls, interface calls, and tool calls are connected according to the upstream and downstream relationships generated by each execution node. The sequential relationship between nodes is determined based on the actual execution time, resulting in an execution state chain. Specifically: the call chain is reconstructed based on the permission context mapping; the call relationship between nodes is established according to the association identifier of each execution node; the upstream and downstream connections of nodes are determined based on the call relationship, resulting in a node association chain; the actual start and end times of each execution node in the node association chain are obtained; the sequential relationship between adjacent execution nodes is determined according to the start and end times; and nodes with overlapping times are marked... The nodes are denoted as parallel execution nodes, and a temporal association chain is obtained. Based on the temporal association chain, multiple model, interface and tool call branches corresponding to the same upstream node are identified, and each call branch is connected to the corresponding upstream node to obtain a branch association chain. The subsequent aggregation node is determined according to the call results in the branch association chain. The completed branch call results are connected to the corresponding subsequent nodes. For repeated calls after failure, a retry relationship is established according to the association identifier between the original call node and the retry node to obtain a complete call chain. Each execution node in the complete call chain is associated with the corresponding permission status and context version, and arranged continuously according to the request execution direction to obtain an execution status chain. By implementing state marking on the execution state chain, the nodes are marked with normal call, repeated call, failure retry, node switching and abnormal termination states according to the actual execution results of the nodes. The actual model, interface and token consumption corresponding to each state are associated with the execution node to obtain the actual execution state set. The actual execution state set is used to characterize the actual execution state and corresponding execution data of each execution node. Based on the execution permission difference comparison of the actual execution status set, the actual model, interface, token consumption and execution time are compared with the original permission constraints to locate the deviation between the actual execution and the permission constraints, and obtain the permission execution deviation set. The permission execution deviation set is used to characterize the difference relationship between the actual execution data of each execution node and the corresponding permission constraints. The system updates the call status based on the permission execution deviation set. Specifically, it obtains the actual token consumption, execution time, and call node from the permission execution deviation set; calculates the quota difference between the actual token consumption and the original available quota for the corresponding stage; converts the quota difference into the remaining quota for the current request; obtains the quota update result; obtains the original validity period of the current permission based on the quota update result; calculates the remaining validity period based on the actual execution time; obtains the corresponding model and interface access results based on the actual call node; compares the actual access results with the original permission allowance range; and associates the quota update result, the validity period update result, and the access status update result with the same request identifier and writes them into the current permission status record to obtain the updated call status data. By performing version control on the updated call status data, a status version and execution sequence are written for the call status, and the status changes generated concurrently are merged to obtain a consistent call status. The consistent call status is used to characterize the current call quota, permission period, model and interface access status determined after version verification and concurrent merging, as well as the corresponding latest status version. Based on the consistent call status, permission change determination is performed. The updated quota, model, interface, and expiration status are compared with the previous permission status to identify status changes that meet the dynamic authentication conditions, and an authentication iteration marker is obtained. Specifically, this involves: obtaining the current remaining quota, remaining permission expiration, model access status, and interface access status from the consistent call status; extracting the corresponding quota, expiration, and access scope from the previous permission status according to the request identifier and status version; calculating the change in quota, expiration, and access scope between the current and previous permission statuses to obtain status change data; determining the current remaining quota based on the quota change; determining the expiration change based on the expiration; and determining the access scope change based on the model and interface access status. The remaining quota, expiration, and access scope changes are then categorized. The authentication trigger threshold is compared with the corresponding authentication trigger threshold, and the status change items that reach the trigger threshold are filtered to obtain the status items to be authenticated. According to the change type corresponding to the status items to be authenticated, the preset authentication trigger rules are matched to determine the corresponding authentication trigger reason and the permission range that needs to be re-determined. The request identifier, current status version, authentication trigger reason and permission range to be determined are associated to generate an authentication iteration flag. The preset authentication trigger rules are: when the remaining quota is lower than the quota threshold, quota authentication is triggered; when the remaining permission period is lower than the period threshold, period authentication is triggered; when the actual call to the model or interface exceeds the authorized scope, access authentication is triggered; when a model or interface switch occurs, forced authentication is triggered. An authentication trigger event is generated when any condition is met. The authentication iteration flag is used to represent the re-authentication status of the current request and records the trigger reason, judgment range and corresponding status version. Based on the authentication iteration marker, the permission status is iterated. The actual execution cost, permission deviation and the latest status version are written into the next round of authentication input, and the permission status token is regenerated to obtain the iterative permission status. The iterative permission status is used to represent the current permission range and effective status after dynamic authentication update. Based on the iterative permission status, the permission decision is re-executed, and the updated model route, interface access scope, token amount and permission period are passed to the subsequent request processing flow to complete the call status backtracking and dynamic authentication iteration.

[0029] In this embodiment, based on the execution permission difference comparison of the actual execution state set, the actual model, interface, token consumption, and execution time are compared with the original permission constraints to locate the deviation between the actual execution and the permission constraints, thus obtaining the permission execution deviation set, as follows: Based on the actual execution state set, the actual call order of the current request is reconstructed, and the corresponding permission constraints are associated to establish a permission execution baseline trajectory. The permission execution baseline trajectory is used to characterize the node order and call path that the current request is allowed to execute under the given permission constraints. The actual execution nodes are mapped to the permission execution baseline trajectory according to the call relationship, the actual call sequence is rearranged, and the model, interface and tool call branches are associated to obtain the actual call trajectory. The actual call trajectory is used to characterize the model, interface and tool nodes that the current request actually passes through and their actual call order. The actual call trajectory is matched with the baseline trajectory for permission execution, identifying newly added, missing, replaced, and sequentially changed nodes, and calculating the corresponding trajectory offset to obtain the permission trajectory deviation set. Specifically, each execution node in the actual call trajectory is obtained, and node identifiers are extracted sequentially according to the call sequence number. Using the actual call node as the matching starting point, the corresponding baseline node is searched in the baseline trajectory for permission execution according to the same call level and adjacent call relationships to establish an initial matching relationship between the actual node and the baseline node. Based on the initial matching relationship, the model identifier, interface identifier, and tool identifier are compared node by node to determine whether there are differences in the calling objects between the actual node and the baseline node. If no corresponding baseline node can be found, the actual node will be excluded. The actual nodes are identified as new nodes, and the actual nodes with corresponding baseline nodes but whose calling objects have changed are identified as replacement nodes. The actual nodes are rearranged according to the calling sequence number of the matched nodes in the baseline trajectory, and the baseline nodes that do not appear in the actual calling trajectory are identified as missing nodes. The actual calling sequence number after rearrangement is compared with the baseline calling sequence number to determine the node order change and obtain the order deviation nodes. The node position difference and calling level difference are calculated based on the actual calling position and baseline calling position of each order deviation node to obtain the corresponding trajectory offset. The new, missing, replacement and order deviation nodes are associated with the corresponding trajectory offset according to the request identifier to form the permission trajectory deviation set. The permission trajectory deviation set is associated with the token consumption, retry count, and execution time of the corresponding node. Resource consumption changes are calculated according to the call order, and continuously increasing resource consumption branches are identified to obtain a resource consumption trend set. Specifically, this involves: obtaining each deviation node in the permission trajectory deviation set, extracting the corresponding token consumption, retry count, and execution time from the actual call trajectory according to the node identifier, associating each resource data with the corresponding deviation node to form a node resource record, sorting the node resource records according to the parent-child node relationship in the actual call trajectory, and calculating the token consumption between adjacent nodes. The changes in node resources are obtained by analyzing the difference, the number of retries, and the execution time. The changes in node resources are accumulated level by level along each parent-child call relationship to determine the cumulative change in resources for each call branch. Call branches with a cumulative increase in resources for multiple consecutive nodes are identified as resource growth branches. The resource change magnitude of consecutive nodes is calculated for resource growth branches according to the call order. Call segments with continuously increasing resource consumption are identified. The corresponding trajectory offset nodes are associated with resource growth segments to form resource consumption change chains for each call branch. The resource consumption change chains are aggregated according to the request identifier and the call branch to obtain a resource consumption trend set. Based on the permission trajectory deviation set and resource consumption trend set, an association judgment is performed. The direction of subsequent permission contraction, maintenance, or expansion is determined according to the degree of trajectory deviation and changes in resource consumption, generating a dynamic permission boundary. Specifically, this involves: obtaining each deviation node and its corresponding trajectory offset in the permission trajectory deviation set; tracing the subsequent call path of the deviation node according to the node connection relationship in the actual call trajectory; transmitting the Token growth, retry accumulation, and execution time changes corresponding to the resource consumption trend set along the call path to obtain a deviation resource transmission chain; calculating the degree of trajectory offset transmission to subsequent nodes and the cumulative impact of resource consumption based on the deviation resource transmission chain; determining the impact range of the current deviation on subsequent permissions based on the transmission changes between adjacent nodes; associating the current permission boundary in reverse along the call path; calculating the actual demand changes of each subsequent node in model access, interface access, and Token quota; updating the corresponding permission parameters based on the demand changes to obtain the permission boundary change; writing the permission boundary change to subsequent unexecuted nodes according to the call order to form a permission boundary that dynamically changes with the actual call trajectory; and associating the current boundary version with the corresponding deviation resource transmission chain to obtain the dynamic permission boundary. Based on the dynamic permission boundary, the token amount, model, and interface access range of subsequent execution nodes are adjusted. Calls exceeding the boundary are subject to quota, switching, or termination processing to obtain the adjusted permission execution status. The permission execution status is used to characterize the actual executable permissions of the current execution node after the dynamic permission boundary adjustment. The adjusted permission execution status is compared with the actual call trajectory again, and the corresponding trajectory offset and resource consumption changes are associated. According to the actual deviations of the execution node aggregation model, interface, token and call sequence, a permission execution deviation set is formed. The permission execution deviation set is used to record the actual deviation of each execution node relative to the permission execution baseline trajectory.

[0030] Example 2, Figure 2 This invention presents a system for controlling secure API calls based on dynamic permission policies in a large-scale model. The system includes a dynamic authentication module, a request adjudication module, a permission convergence module, and a state backtracking module, with connections between the modules. The dynamic authentication module is used to obtain call status data and perform dynamic authentication to generate permission status tokens. The request adjudication module is used to execute request adjudication based on the permission status token and generate permission constraint instructions; The permission convergence module is used to implement permission convergence by applying permission constraint instructions to obtain controlled API requests; The status backtracking module is used to perform call status backtracking based on controlled API requests, update call status data, and trigger dynamic authentication iteration.

[0031] The above embodiments can be implemented, in whole or in part, by software, hardware, firmware, or any other combination thereof. When implemented using software, the above embodiments can be implemented, in whole or in part, in the form of a computer program product.

[0032] Those skilled in the art will recognize that the modules and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0033] In addition, the functional modules in the various embodiments of this application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module.

[0034] The above description is merely a specific technical solution of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

[0035] In conclusion, the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A method for controlling secure API calls in a large model based on dynamic permission policies, characterized in that, include: Obtain the call status data and perform dynamic authentication to generate an access status token; Execute request adjudication based on permission status tokens and generate permission constraint instructions; Controlled API requests are obtained by implementing permission convergence on permission constraint instructions; Implement call status backtracking based on controlled API requests, update call status data, and trigger dynamic authentication iteration.

2. The method for controlling secure API calls based on dynamic permission policies according to claim 1, characterized in that, The process of obtaining call status data and performing dynamic authentication to generate an access status token is as follows: Obtain the call status data and perform call subject parsing to determine the current call subject status; Based on the current calling entity status, obtain model access permissions, interface access permissions, and token quota status, and perform permission boundary reorganization to form entity permission boundaries; Receive the large model API request initiated by the current calling entity, parse the request credentials, target model and target interface, and perform request entity binding to obtain the current request status; Obtain the real-time usage status of the current subject based on the current request status, and perform usage status aggregation to determine the current call status; Based on the current invocation status, dynamic permission pruning is performed on the subject's permission boundaries, and the permission scope is shrunk to determine the real-time permission boundaries; Dynamic authentication is performed on the current request status based on real-time permission boundaries, and request-level permission determination is implemented to generate the request authorization scope; Based on the scope of authorization requests, permissions are bound to the API key, the calling entity, and the request identifier to limit the current API call chain and form a call permission binding state. By calling the permission binding state analysis, the validity period of the permission, the scope of allowed models, and the scope of allowed interfaces are analyzed, and the permission state is assembled to form a token payload; Securely bind the token payload with the calling entity identifier, request identifier, and API key, and perform token issuance to form an authorization status token.

3. The method for controlling secure API calls based on dynamic permission policies according to claim 2, characterized in that, The process of dynamically pruning permissions based on the current invocation state and shrinking the permission scope to determine real-time permission boundaries is as follows: Based on the current call status, a hierarchical occupancy chain is established for employee quotas, department quotas, and API key quotas, forming a quota occupancy sequence; The API requests currently being executed by the employee and their department are identified by the quota occupancy sequence, and the concurrent occupancy intervals are divided to form real-time occupancy intervals; The available quota range corresponding to the current API request is determined based on the real-time occupancy interval, and the current request token occupancy status is placed into the available quota range to form the available quota range for the request. Based on the available quota range, iterate through the model access range within the main permission boundary and shrink the permissions to form a model interface permission chain; Based on the model interface permission chain, the target model and target interface of the current request are determined, and the executable call scope of the current request is narrowed to form the real-time permission scope of the request; By requesting real-time permission scope, the current API key, calling subject, and request identifier are limited to the model, interface, and token amount, and the limited state is attached to the current API call request to form a request permission constraint state. Based on the request permission constraint state, the scope of permission is transferred to form a real-time permission boundary.

4. The method for controlling secure API calls based on dynamic permission policies according to claim 1, characterized in that, The process of executing request adjudication based on permission status tokens and generating permission constraint instructions is as follows: Extract the calling entity identifier, API key identifier, and request identifier based on the permission status token, locate the request context, establish a request index for the token, and form a token request location node; Based on the token request, the node reads the permission version, key status version, and permission validity period, divides the token's available time period, maps the permission version and key status version to the time period, and obtains the token's validity slice. Based on token validity period slicing, the target model and target interface are parsed, the model service route and interface processing path are located, and the request access path is generated. Based on the requested access path, obtain employee permissions, department permissions, API key permissions, and token permissions, and perform hierarchical intersection processing on the model access scope to form model intersection permissions; Based on the intersection of models, the access scope of the interface is obtained, and the quota pre-occupancy analysis is performed to form the request quota pre-occupancy status. Identify the current quota gap based on the quota pre-occupancy status, obtain the model interface combination that meets the remaining quota for replacement matching, and generate the request model interface adjustment status. Based on the request model interface adjustment state, determine the final target model, target interface and token amount, and organize the model routing, interface path and limit to obtain the request execution path; Extract the model routing node, interface processing node, and token limit according to the request execution path, and organize them into various fields to form a constraint instruction field set; The execution entry point is determined based on the constraint instruction field set. Each field is then passed sequentially to the model routing service and the model call adaptation layer, and the instructions are encapsulated to form permission constraint instructions.

5. A method for controlling secure API calls based on dynamic permission policies according to claim 4, characterized in that, The process of obtaining the interface access range based on model intersection permissions and performing quota pre-allocation analysis to form a request quota pre-allocation status is as follows: The model interface combination is determined based on the intersection permissions of the models, and the token consumption items are divided to form request token measurement items; The token demand of the current request is collected based on the token metering item, and the interface consumption is added to form the token demand range. The demand range is then limited to form the request token demand segment. The request token demand segments are mapped sequentially and the available range is divided to form a multi-level quota mapping chain; Based on the multi-level quota mapping chain, concurrent requests are associated and the quota occupancy order is arranged, and the quota that is about to be released is included in the available range to form a concurrent quota occupancy sequence; Based on the concurrent quota usage sequence, the request Token demand segment is shrunk, and the part exceeding any quota boundary is truncated, retaining the Token range that can be carried by each quota level, forming the request pre-occupied quota segment; Based on the requested pre-occupied quota segment, the tiered quota atomic allocation is performed, and the request identifier and the allocated quota are written into the quota allocation record. The remaining quota at each level is updated synchronously to form the requested quota pre-occupancy record. Based on the requested quota pre-allocation record, the quota occupancy results at each level are aggregated and associated with the model interface and the pre-allocated Token quota to form the requested quota pre-allocation status.

6. The method for controlling secure API calls based on dynamic permission policies according to claim 1, characterized in that, The controlled API requests are obtained by implementing permission convergence on permission constraint instructions, as detailed below: The model routing, interface access, token amount and permission period are parsed through permission constraint instructions, and the constraint items are sorted to establish a request constraint processing sequence. Based on the request constraint processing sequence, the model route is replaced, and the call content that cannot enter the restricted service node is removed, resulting in a model-restricted request; Based on the model-restricted request, the interface path is rewritten, and the interface address and call direction in the original request are replaced to form an interface-restricted request; Based on the restricted requests from the interface, the quota is divided into stages, and a stage quota control segment is generated; The request content is compressed by implementing a phased quota control segment, the current request content is segmented, and content exceeding the quota is gathered to form a reconstructed request content; Based on the reconstructed request content, the request data is replaced and the call content in the original request is overwritten, resulting in a restricted request generation stage; The execution chain is progressively implemented based on the phased restricted requests, and overdue execution data is truncated to form a time-limited execution chain; Execution data is solidified through a time-limited execution chain, forming a permission convergence context; The request structure is restructured based on the permission convergence context, while retaining the original request identifier, and a controlled API request is generated.

7. A method for controlling secure API calls based on dynamic permission policies for large-scale APIs according to claim 6, characterized in that, The process of compressing request content through a phased quota control segment, segmenting the current request content, and consolidating content exceeding the quota to form reconstructed request content is as follows: Based on the phased quota control segment, the content is segmented, the content boundaries are defined, and each content segment is measured with a Token, the Token usage is marked, and the requested content segment set is obtained. Based on the request content segment set, implement quota mapping, write the available Token quota for each stage into the content segment, calculate the difference between the Token usage and the available quota, and obtain the stage quota allocation table. By performing content convergence on the phase quota allocation table, the phase convergence content set is obtained; Structural compression is performed based on the stage-converged content set. Adjacent messages are merged, duplicate content is converged, and the content length is adjusted to obtain the stage-reconstructed content. Based on the phased reconstruction content, a request for reorganization is implemented, and the token usage after reorganization is remeasured to obtain the actual token usage result; By implementing quota feedback on the actual token usage results, calculating the difference between the actual token usage and the available quota for the stage, locating the content segment that caused the quota deviation, updating the available quota for subsequent stages, and performing boundary convergence and structural compression on the content segment again to obtain dynamically reconstructed content. Based on the dynamic reconstruction content, a request write-back is implemented to synchronously update the message index, role field, tool data, and token occupancy marker, thereby obtaining the reconstruction request content.

8. A method for controlling secure API calls based on dynamic permission policies according to claim 1, characterized in that, The process of implementing call status backtracking based on controlled API requests, updating call status data, and triggering dynamic authentication iteration is as follows: Based on the controlled API request execution permission context, and synchronously transmitted with model and tool calls, a permission context mapping is established; The call chain is reconstructed based on the permission context mapping to obtain the execution state chain; By implementing state marking on the execution state chain and associating the actual model, interface, and token consumption of each state with the execution node, the actual execution state set is obtained; By comparing the execution permission difference based on the actual execution status set, the deviation between the actual execution and the permission constraints is located, and the permission execution deviation set is obtained. Based on the permission-based execution deviation set, the state is updated, and the model and interface states are updated to obtain the updated call state data; By performing version control on the update call status data and merging versions of concurrently generated status changes, a consistent call status is obtained. Based on the consistent call status execution permission change judgment, identify the status change that meets the dynamic authentication conditions and obtain the authentication iteration mark; Based on the authentication iteration flag, the permission status is iterated and a new permission status token is generated to obtain the iterated permission status. Based on the iterative permission status, the permission decision is re-executed, and the updated model route, interface access scope, token amount, and permission duration are passed to the subsequent request processing flow.

9. A method for controlling secure API calls based on dynamic permission policies for large-scale models, as described in claim 8, is characterized in that... The step of comparing the execution permission difference based on the actual execution status set to locate the deviation between the actual execution and the permission constraints yields a permission execution deviation set, as detailed below: Based on the actual execution state set, the actual call order of the current request is reconstructed, and permission constraints are associated to establish a baseline trajectory for permission execution; The actual execution nodes are mapped to the permission execution baseline trajectory, the actual call sequence is rearranged, and the model, interface and tool call branches are associated to obtain the actual call trajectory; Node matching is performed between the actual call trajectory and the baseline trajectory for permission execution, and the trajectory offset is calculated to obtain the permission trajectory deviation set; By associating the permission trajectory deviation set with the node's token consumption, retry count, and execution time, we can calculate the changes in resource consumption, identify continuously increasing resource consumption branches, and obtain a resource consumption trend set. Based on the set of deviations in permission trajectories and the set of trends in resource consumption, an association determination is performed to determine the direction of subsequent permission contraction, maintenance, or expansion, and dynamic permission boundaries are generated. Based on dynamic permission boundaries, the token amount, model, and interface access range of subsequent execution nodes are adjusted. Calls exceeding the boundaries are subject to limits, switching, or termination processing to obtain the permission execution status. The permission execution status is compared again with the actual call trajectory, the trajectory offset and resource consumption changes are correlated, and the actual deviations are collected to form a permission execution deviation set.

10. A system using a large-scale API security call control method based on dynamic permission policies as described in any one of claims 1-9, characterized in that, It includes a dynamic authentication module, a request adjudication module, a permission convergence module, and a status backtracking module, and these modules are interconnected. The dynamic authentication module is used to obtain call status data and perform dynamic authentication to generate permission status tokens. The request adjudication module is used to execute request adjudication based on the permission status token and generate permission constraint instructions; The permission convergence module is used to implement permission convergence by applying permission constraint instructions to obtain controlled API requests; The status backtracking module is used to perform call status backtracking based on controlled API requests, update call status data, and trigger dynamic authentication iteration.

Citation Information

Patent Citations

  • API (Application Program Interface) execution method and device for dynamic authority control and storage medium

    CN121071908A

  • Method and system for realizing large model access authentication and flow control based on APISIX gateway

    CN121508935A