@@ -33,4 +33,79 @@ public void CanConfigureClients()
3333 Assert . Equal ( "openai" , openai . GetRequiredService < ChatClientMetadata > ( ) . ProviderName ) ;
3434 Assert . Equal ( "xai" , grok . GetRequiredService < ChatClientMetadata > ( ) . ProviderName ) ;
3535 }
36+
37+ [ Fact ]
38+ public void CanOverrideClientId ( )
39+ {
40+ var configuration = new ConfigurationBuilder ( )
41+ . AddInMemoryCollection ( new Dictionary < string , string ? >
42+ {
43+ [ "ai:clients:grok:id" ] = "xai" ,
44+ [ "ai:clients:grok:modelid" ] = "grok-4-fast" ,
45+ [ "ai:clients:grok:apikey" ] = "xai-asdfasdf" ,
46+ [ "ai:clients:grok:endpoint" ] = "https://api.x.ai" ,
47+ } )
48+ . Build ( ) ;
49+
50+ var calls = new List < string > ( ) ;
51+
52+ var services = new ServiceCollection ( )
53+ . AddSingleton < IConfiguration > ( configuration )
54+ . UseChatClients ( configuration )
55+ . BuildServiceProvider ( ) ;
56+
57+ var grok = services . GetRequiredKeyedService < IChatClient > ( "xai" ) ;
58+
59+ Assert . Equal ( "xai" , grok . GetRequiredService < ChatClientMetadata > ( ) . ProviderName ) ;
60+ }
61+
62+ [ Fact ]
63+ public void CanSetApiKeyToConfiguration ( )
64+ {
65+ var configuration = new ConfigurationBuilder ( )
66+ . AddInMemoryCollection ( new Dictionary < string , string ? >
67+ {
68+ [ "keys:grok" ] = "xai-asdfasdf" ,
69+ [ "ai:clients:grok:modelid" ] = "grok-4-fast" ,
70+ [ "ai:clients:grok:apikey" ] = "keys:grok" ,
71+ [ "ai:clients:grok:endpoint" ] = "https://api.x.ai" ,
72+ } )
73+ . Build ( ) ;
74+
75+ var calls = new List < string > ( ) ;
76+
77+ var services = new ServiceCollection ( )
78+ . AddSingleton < IConfiguration > ( configuration )
79+ . UseChatClients ( configuration )
80+ . BuildServiceProvider ( ) ;
81+
82+ var grok = services . GetRequiredKeyedService < IChatClient > ( "grok" ) ;
83+
84+ Assert . Equal ( "xai" , grok . GetRequiredService < ChatClientMetadata > ( ) . ProviderName ) ;
85+ }
86+
87+ [ Fact ]
88+ public void CanSetApiKeyToSection ( )
89+ {
90+ var configuration = new ConfigurationBuilder ( )
91+ . AddInMemoryCollection ( new Dictionary < string , string ? >
92+ {
93+ [ "keys:grok:apikey" ] = "xai-asdfasdf" ,
94+ [ "ai:clients:grok:modelid" ] = "grok-4-fast" ,
95+ [ "ai:clients:grok:apikey" ] = "keys:grok" ,
96+ [ "ai:clients:grok:endpoint" ] = "https://api.x.ai" ,
97+ } )
98+ . Build ( ) ;
99+
100+ var calls = new List < string > ( ) ;
101+
102+ var services = new ServiceCollection ( )
103+ . AddSingleton < IConfiguration > ( configuration )
104+ . UseChatClients ( configuration )
105+ . BuildServiceProvider ( ) ;
106+
107+ var grok = services . GetRequiredKeyedService < IChatClient > ( "grok" ) ;
108+
109+ Assert . Equal ( "xai" , grok . GetRequiredService < ChatClientMetadata > ( ) . ProviderName ) ;
110+ }
36111}
0 commit comments