Skip to content

[Bug] session.error with t.asString is not a function when using session.send() with BYOK provider #1127

@Akhand-99

Description

@Akhand-99

## Description

When using the Python SDK with a BYOK provider (tested with Azure OpenAI and Anthropic) and sending a prompt via session.send({"prompt": "..."}), every query results in a session.error event with the message t.asString is not a function. No assistant.message event is ever received — the session silently goes idle.

This makes the SDK completely unusable with BYOK when following the documented session.send() pattern.

## Environment

  • SDK version:* github-copilot-sdk==0.2.2
  • CLI binary version:* copilot.exe v1.0.21 (bundled)
  • Python version:* 3.13
  • OS:* Windows 11
  • Providers tested:* Azure OpenAI (type: "azure"), Anthropic (type: "anthropic")

## Steps to Reproduce

  1. Install the SDK:
pip install github-copilot-sdk==0.2.2
  1. Create and run the following script with a valid BYOK provider and API key:
import asyncio

import os

from dotenv import load_dotenv

from copilot import CopilotClient

from copilot.session import PermissionHandler

load_dotenv()

FOUNDRY_MODEL_URL = "https://<your-resource>.openai.azure.com/"

async def main():

client = CopilotClient()

await client.start()

session = await client.create_session(

on_permission_request=PermissionHandler.approve_all,

model="<your-deployment-name>",

provider={

"type": "azure",

"base_url": FOUNDRY_MODEL_URL,

"api_key": os.environ["FOUNDRY_API_KEY"],

},

available_tools=[],

infinite_sessions={"enabled": False},

)

done = asyncio.Event()

def on_event(event):

print(f"Received event: {event.type.value}")

if event.type.value == "assistant.message":

print(event.data.content)

elif event.type.value == "session.error":

print(f"error_type={event.data.error_type!r}  message={event.data.message!r}")

done.set()

elif event.type.value == "session.idle":

done.set()

session.on(on_event)

await session.send({"prompt": "What is 2+2?"})

await done.wait()

await session.disconnect()

await client.stop()

asyncio.run(main())

## Actual Behaviour

The session.error event fires with t.asString is not a function. No assistant.message event is received. The session then goes idle.


Received event: pending_messages.modified

Received event: pending_messages.modified

Received event: session.info

Received event: session.tools_updated

Received event: session.error

error_type='query'  message='t.asString is not a function'

Received event: session.idle

## Expected Behaviour

A session.error event should not be fired. A assistant.message event should be received containing the model's response content.

## Additional Notes

  • Verified the BYOK endpoint itself is healthy — a direct HTTP call to the Azure OpenAI API returns a valid 200 response:
{

"choices": [

{

"finish_reason": "stop",

"message": { "content": "2 + 2 equals **4**.", "role": "assistant" }

}

],

"model": "gpt-4o-2024-11-20",

"usage": {

"completion_tokens": 11,

"prompt_tokens": 14,

"total_tokens": 25

}

}
  • The error occurs regardless of provider type ("azure", "openai", "anthropic").
  • The error occurs regardless of whether available_tools=[] is set.
  • The reproduction code was written by following the example in docs/auth/byok.md in this repository.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    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