ZZYhho commented on issue #13150:
URL: https://github.com/apache/apisix/issues/13150#issuecomment-4182031485

   @Baoyuantop Sorry,I will decribe it detail.
   - To implement AI billing/accounting within our company, we have created 
multiple API Keys (SKs) at the provider side. Our goal is to store these keys 
at the Consumer level (using either labels or metadata) and pass them 
dynamically as variables to the ai-proxy plugin, which is configured on the 
Route side.
   
   However, when I attempted to use labels to pass the credentials, the request 
failed with a 401 Unauthorized error. It seems the ai-proxy plugin is not 
correctly picking up the variable from the consumer context.
   
   Q:
   1. Does the ai-proxy plugin support reading credentials from Consumer labels 
or metadata via variables?
   2. If this is not natively supported, what is the recommended workaround to 
achieve per-consumer SK injection for AI billing?
   
   ### Current Configuration (Example)
   #### Consumer:
   
   ``` json
   {
       "username": "internal-team-a",
       "plugins": {
           "key-auth": {
               "key": "auth-key-for-team-a"
           }
       },
       "labels": {
           "provider_sk": "sk-xxxxxxxxxxxx"
       },
       "metadata": {
           "provider_sk": "sk-xxxxxxxxxxxx"
       }
   }
   ```
   #### Route:
   
   ```json
   {
       "uri": "/v1/chat/completions",
       "plugins": {
           "ai-proxy": {
               "auth": {
                   "header": {
                       "Authorization": "$consumer_labels_provider_sk" 
                   }
               },
               "model": {
                   "provider": "openai",
                   "name": "gpt-4"
               }
           }
       }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to