AgnesAI-Models icon indicating copy to clipboard operation
AgnesAI-Models copied to clipboard

[API]: 401 Invalid token with China-site API key

Open Gerald-Qiu opened this issue 1 month ago • 4 comments

Model

agnes-image-2.5-flash

Endpoint

POST /v1/images/generations

SDK or client

Python 3.9 standard-library urllib (local backend)

Minimal sanitized request

Portal: Agnes China site (agnes-ai.cn)
Base URL currently used: https://apihub.agnes-ai.com/v1
Authorization header: Authorization: Bearer [REDACTED]
Sanitized request body (reference images omitted):
{"model":"agnes-image-2.5-flash","prompt":"[try-on prompt omitted]","size":"1K","ratio":"9:16","extra_body":{"image":["[pet image omitted]","[garment image omitted]"],"response_format":"url"}}

Request IDs:
- Standard header: 20261031070602139555324yz6Z49GI
- Trailing-space diagnostic: 20261031070154760029012jTGmVDc9

Question: Should a China-site API key use https://apihub.agnes-ai.cn/v1 instead of this .com base URL?

Error response

HTTP 401: Invalid token. Standard-format request ID: 20261031070602139555324yz6Z49GI. A diagnostic request with trailing whitespace after the key also returned 401 (request ID: 20261031070154760029012jTGmVDc9).

Expected behavior

Expected: a key created in the China-site console authenticates with the correct regional API base URL and returns a pet try-on image. Please confirm whether this key should use the .cn endpoint.

Actual behavior

Actual: every image-generation attempt returns HTTP 401 Invalid token before an image is produced. I created and checked the key in the China-site console. The app currently uses the international .com base URL and sends the standard ASCII Authorization: Bearer [REDACTED] header. Adding trailing whitespace after the key did not change the result. The key and reference images are omitted from this report.

Is this reproducible?

Yes

Gerald-Qiu avatar Oct 31 '26 07:10 Gerald-Qiu

Yes. API keys are region-specific. Please use the China-site API key with the China-site endpoint:

https://api.agnes-ai.cn/v1

The international-site API key should be used with the international endpoint:

https://apihub.agnes-ai.com/v1

Your request used a China-site key with the international endpoint, which caused the 401 Invalid token error. Please update the base URL and try again.

Agnes-Yn avatar Nov 02 '26 03:11 Agnes-Yn

Thanks for confirming the China-site endpoint. I replaced the key with a newly generated China-site API key and updated the backend to use https://api.agnes-ai.cn/v1.

However, a read-only request to GET https://api.agnes-ai.cn/v1/models still returns 401 Invalid token.

Request ID: 202611040826326996969058MalUvUP

Could you please check whether the new China-site key is active and enabled for API access? I have not included the key in this report.

Gerald-Qiu avatar Nov 04 '26 08:11 Gerald-Qiu

Hi,

We've looked into this error.

Request: 202611040826326996969058MalUvUP, 2026-11-04 16:26:32 (UTC+8), endpoint GET /v1/models Result: 401 — "Invalid token"

Cause: Your API key could not be authenticated — this is not a model issue, not a service incident, and not a balance issue (insufficient balance returns 402).

Please check the following:

Is the key issued by the correct site?​ Keys created on the China site and the International (Singapore) site are not interchangeable. Has the key been deleted or regenerated?​ If you created a new key, make sure your code uses the new one. Is the request header correct?​ It must be Authorization: Bearer sk-xxxx. The Bearer prefix and the space after it are both required. Please copy a fresh key from the console and try again.

Agnes-Yn avatar Nov 05 '26 04:11 Agnes-Yn

Hi Agnes team,

Thanks for your guidance. I created a new API key, updated my local .env file, and tested using the updated value.

The request header is sent in the standard format Authorization: Bearer <API_KEY>, with one ASCII space after Bearer. I did not include the key in this message.

Using the same key, I tested both endpoints:

  • GET https://api.agnes-ai.cn/v1/models returned 401 Invalid token. Request ID: 20261106133428673102553vLJqwoeM (2026-11-06 13:34:28 UTC).
  • GET https://apihub.agnes-ai.com/v1/models returned 401 Invalid token. Request ID: 20261106133428959399021I16gcUGz (2026-11-06 13:34:28 UTC).

Could you please check these request IDs and confirm whether the new key is active and which site or region issued it? Please also confirm which base URL this key should use.

Can you see the complete request details associated with these request IDs, including the request path and headers? If so, could you confirm whether the request format is correct on your side? These were GET requests, so they did not include a request body.

I stopped after the authentication checks, so I did not submit an image-generation request.

Thank you.

Gerald-Qiu avatar Nov 06 '26 13:11 Gerald-Qiu