Skip to content

Unclosed client session when using some litellm models #1016

Open
@lvicentesanchez

Description

@lvicentesanchez

Describe the bug

When using the litellm extension with models like gemini/gemini-2.5-flash or anthropic/... you get the following message when the app finishes:

Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fd44a73b890>
Unclosed connector
connections: ['deque([(<aiohttp.client_proto.ResponseHandler object at 0x7fd44a7034d0>, 9465.214257948)])']
connector: <aiohttp.connector.TCPConnector object at 0x7fd449d71610>

Debug information

  • Agents SDK version: (e.g. v0.0.3)
  • Python version (e.g. Python 3.10)

Repro steps

import asyncio
import os

from agents import (
    Agent,
    ModelSettings,
    Runner,
    set_tracing_disabled,
)
from agents.extensions.models.litellm_model import LitellmModel
from dotenv import load_dotenv

set_tracing_disabled(True)
load_dotenv(override=True)


agent = Agent(
    name="Trivia assistant",
    instructions="You are a helpful and informative trivia assistant.",
    model=LitellmModel(
        model="gemini/gemini-2.5-flash",
        api_key=os.getenv("GEMINI_API_KEY"),
    ),
    model_settings=ModelSettings(temperature=0.2, top_p=0.95),
)


async def main():
    result = await Runner.run(
        agent,
        input=(
            "Calculate how long it takes to the fastest land animal to run through the longest continuous road. "
            "Only take into account roads without gaps or interruptions."
        ),
    )
    print(result.final_output)


if __name__ == "__main__":
    asyncio.run(main())

Expected behavior

As with other models supported by litellm, we shouldn't seen this message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions