Skip to content

429 Too many requests on /api/v2/oauth with concurrent embedding invocations #275

@mkhludnev

Description

@mkhludnev

Hi.

I spin off multiple (just 2 so far) concurrent tasks for embeddings requests:

async with asyncio.TaskGroup() as tg:
    for url in urls:
         tg.create_task(invoke_gigachat_embeddings(url))

it seems if oauth token needs to be refreshed it's done simultaneously and falls with:

line 158, in _build_vectors
    batch_embeddings = await giga_embeddings.aembed_documents(list(texts))
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/app/.local/lib/python3.12/site-packages/langchain_gigachat/embeddings/gigachat.py", line 177, in aembed_documents
    embeddings = await self._client.aembeddings(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/app/.local/lib/python3.12/site-packages/gigachat/client.py", line 436, in aembeddings
    return await self._adecorator(_acall)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/app/.local/lib/python3.12/site-packages/gigachat/client.py", line 417, in _adecorator
    await self._aupdate_token()
  File "/home/app/.local/lib/python3.12/site-packages/gigachat/client.py", line 388, in _aupdate_token
    self._access_token = await post_auth.asyncio(
                         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/app/.local/lib/python3.12/site-packages/gigachat/api/post_auth.py", line 49, in asyncio
    return build_response(response, AccessToken)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/app/.local/lib/python3.12/site-packages/gigachat/api/utils.py", line 88, in build_response
    raise ResponseError(response.url, response.status_code, response.content, response.headers)
gigachat.exceptions.ResponseError: (URL('https://ngw.devices.sberbank.ru:9443/api/v2/oauth'), 429, b'<html>\r\n<head><title>429 Too Many Requests</title></head>\r\n<
body>\r\n<center><h1>429 Too Many Requests</h1></center>\r\n<hr><center>SynGX</center>\r\n</body>\r\n</html>\r\n', Headers({'server': 'SynGX', 'date': 'Mon, 21 Jul 2025 05:26:50 GMT', 'content-type': 'text/html', 'content-length': '162', 'connection': 'keep-alive', 'allow': 'GET, POST', 'strict-transport-security': 'max-age=3153
6000; includeSubDomains'}))

Can you suggest how to make client app code (I have one idea, btw) or the library code more resilient eg introduce retires or timeouts etc ?
Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions