microsoft / microsoft/teams.net

Stream "API calls quota exceeded"

Open
#112 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
46
Forks
21
Avg merge
22h 25m
Merged PRs (30d)
16

Description

The streaming chat frequently triggers the API quota exceeded error. Any suggestions for optimisation?

```log
2025-09-04 07:40:10.680 +00:00 [ERR] System.Exception: Exception of type 'Microsoft.Teams.Common.Http.HttpException' was thrown.
---> "API calls quota exceeded"
--- End of inner exception stack trace ---
at Microsoft.Teams.Common.Extensions.TaskExtensions.Retry[T](Task`1 task, Int32 max, Int32 delay)
at Microsoft.Teams.Common.Extensions.TaskExtensions.Retry[T](Task`1 task, Int32 max, Int32 delay)
at Microsoft.Teams.Common.Extensions.TaskExtensions.Retry[T](Task`1 task, Int32 max, Int32 delay)
at Microsoft.Teams.Common.Extensions.TaskExtensions.Retry[T](Task`1 task, Int32 max, Int32 delay)
at Microsoft.Teams.Plugins.AspNetCore.AspNetCorePlugin.Stream.Close()
at Microsoft.Teams.Apps.App.Process(ISenderPlugin sender, ActivityEvent event, CancellationToken cancellationToken)
```

```csharp
[Message]
public async Task OnMessage(IContext context, [Context] MessageActivity activity, [Context] IContext.Client client)
{
var state = State.From(context);

using var scope = _serviceScopeFactory.CreateScope();

var chatPrompt = scope.ServiceProvider.GetRequiredService();

var contents = new List();
if (!string.IsNullOrWhiteSpace(context.Activity.Text))
{
contents.Add(new TextContent() { Text = context.Activity.Text });
}
if (context.Activity.Attachments?.Count > 0)
{
_logger.LogInformation("Attachment count: {Count}", context.Activity.Attachments.Count);
await ProcessAttachments(context, contents);
}

var response = await chatPrompt.Send(
content: [.. contents],
options: new() { Messages = state.Messages },
onChunk: (chunk) => Task.Run(() =>
{
context.Stream.Emit(chunk);
}, context.CancellationToken),
cancellationToken: context.CancellationToken
);

var activityWithResponse = new MessageActivity();
activityWithResponse.AddAIGenerated();
context.Stream.Emit(activityWithResponse);
}
```

Contributor guide

Open the contributing guide

Research direction

Start at the OnMessage entry point and trace chatPrompt.Send, the onChunk callback, and context.Stream.Emit alongside the Retry stack in the report. Reproduce the quota error, determine which streaming operations exceed the API limit, and define the optimization and verification steps before making a change.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.