Skip to content

TypeError: StreamReader.readline() got an unexpected keyword argument 'max_line_length' when streaming with aiohttp #2487

@SeleneXX

Description

@SeleneXX

Environment details
───────────────────

• Programming language: Python
• OS: Windows
• Language runtime version: 3.13.3
• Package version: google-genai 2.5.0, aiohttp 3.13.3
Steps to reproduce
──────────────────

  1. Install google-genai and aiohttp in the same environment:
    pip install google-genai==2.5.0 aiohttp==3.13.3

  2. Run any async streaming request:
    import asyncio
    from google import genai

    async def main():
    client = genai.Client(api_key="YOUR_API_KEY")
    async for chunk in client.aio.models.generate_content_stream(
    model="gemini-3.5-flash",
    contents="Hello"
    ):
    print(chunk)

    asyncio.run(main())

  3. The request crashes immediately with:
    TypeError: StreamReader.readline() got an unexpected keyword argument 'max_line_length'
    Root cause
    ──────────

In google/genai/_api_client.py around line 450, the library calls:

line_bytes = await self.response_stream.content.readline(
max_line_length=READ_BUFFER_SIZE
)

However, aiohttp.StreamReader.readline() does not accept any parameters. Its signature is simply:

async def readline(self) -> bytes:
return await self.readuntil()

The max_line_length keyword argument was introduced in PR #2437, but it is incompatible with the actual aiohttp API.

The line-length limit is already governed by the limit parameter of StreamReader,
which is set correctly via read_bufsize=READ_BUFFER_SIZE (4MB) when the aiohttp
ClientSession is created:
https://github.com/googleapis/python-genai/blob/main/google/genai/_api_client.py#L958

Suggested fix
─────────────

Remove the unsupported max_line_length keyword argument:

line_bytes = await self.response_stream.content.readline()

The existing read_bufsize configuration already prevents LineTooLong errors for large SSE lines.

Metadata

Metadata

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions