1+
2+ #nullable enable
3+
4+ namespace Anthropic
5+ {
6+ public partial class AnthropicClient
7+ {
8+ partial void PrepareBetaModelsGetArguments (
9+ global ::System . Net . Http . HttpClient httpClient ,
10+ ref string modelId ,
11+ ref string ? anthropicVersion ,
12+ ref string ? xApiKey ) ;
13+ partial void PrepareBetaModelsGetRequest (
14+ global ::System . Net . Http . HttpClient httpClient ,
15+ global ::System . Net . Http . HttpRequestMessage httpRequestMessage ,
16+ string modelId ,
17+ string ? anthropicVersion ,
18+ string ? xApiKey ) ;
19+ partial void ProcessBetaModelsGetResponse (
20+ global ::System . Net . Http . HttpClient httpClient ,
21+ global ::System . Net . Http . HttpResponseMessage httpResponseMessage ) ;
22+
23+ partial void ProcessBetaModelsGetResponseContent (
24+ global ::System . Net . Http . HttpClient httpClient ,
25+ global ::System . Net . Http . HttpResponseMessage httpResponseMessage ,
26+ ref string content ) ;
27+
28+ /// <summary>
29+ /// Get a Model<br/>
30+ /// Get a specific model.<br/>
31+ /// The Models API response can be used to determine information about a specific model or resolve a model alias to a model ID.
32+ /// </summary>
33+ /// <param name="modelId">
34+ /// Model identifier or alias.
35+ /// </param>
36+ /// <param name="anthropicVersion">
37+ /// The version of the Anthropic API you want to use.<br/>
38+ /// Read more about versioning and our version history [here](https://docs.anthropic.com/en/api/versioning).
39+ /// </param>
40+ /// <param name="xApiKey">
41+ /// Your unique API key for authentication. <br/>
42+ /// This key is required in the header of all API requests, to authenticate your account and access Anthropic's services. Get your API key through the [Console](https://console.anthropic.com/settings/keys). Each key is scoped to a Workspace.
43+ /// </param>
44+ /// <param name="cancellationToken">The token to cancel the operation with</param>
45+ /// <exception cref="global::Anthropic.ApiException"></exception>
46+ public async global ::System . Threading . Tasks . Task < global ::Anthropic . BetaModelResponse > BetaModelsGetAsync (
47+ string modelId ,
48+ string ? anthropicVersion = default ,
49+ string ? xApiKey = default ,
50+ global ::System . Threading . CancellationToken cancellationToken = default )
51+ {
52+ PrepareArguments (
53+ client : HttpClient ) ;
54+ PrepareBetaModelsGetArguments (
55+ httpClient : HttpClient ,
56+ modelId : ref modelId ,
57+ anthropicVersion : ref anthropicVersion ,
58+ xApiKey : ref xApiKey ) ;
59+
60+ var __pathBuilder = new PathBuilder (
61+ path : $ "/v1/models/{ modelId } ?beta=true",
62+ baseUri : HttpClient . BaseAddress ) ;
63+ var __path = __pathBuilder . ToString ( ) ;
64+ using var __httpRequest = new global ::System . Net . Http . HttpRequestMessage (
65+ method : global ::System . Net . Http . HttpMethod . Get ,
66+ requestUri : new global ::System . Uri ( __path , global ::System . UriKind . RelativeOrAbsolute ) ) ;
67+ #if NET6_0_OR_GREATER
68+ __httpRequest . Version = global ::System . Net . HttpVersion . Version11 ;
69+ __httpRequest . VersionPolicy = global ::System . Net . Http . HttpVersionPolicy . RequestVersionOrHigher ;
70+ #endif
71+
72+ foreach ( var __authorization in Authorizations )
73+ {
74+ if ( __authorization . Type == "Http" ||
75+ __authorization . Type == "OAuth2" )
76+ {
77+ __httpRequest . Headers . Authorization = new global ::System . Net . Http . Headers . AuthenticationHeaderValue (
78+ scheme : __authorization . Name ,
79+ parameter : __authorization . Value ) ;
80+ }
81+ else if ( __authorization . Type == "ApiKey" &&
82+ __authorization . Location == "Header" )
83+ {
84+ __httpRequest . Headers . Add ( __authorization . Name , __authorization . Value ) ;
85+ }
86+ }
87+
88+ if ( anthropicVersion != default )
89+ {
90+ __httpRequest . Headers . TryAddWithoutValidation ( "anthropic-version" , anthropicVersion . ToString ( ) ) ;
91+ }
92+ if ( xApiKey != default )
93+ {
94+ __httpRequest . Headers . TryAddWithoutValidation ( "x-api-key" , xApiKey . ToString ( ) ) ;
95+ }
96+
97+
98+ PrepareRequest (
99+ client : HttpClient ,
100+ request : __httpRequest ) ;
101+ PrepareBetaModelsGetRequest (
102+ httpClient : HttpClient ,
103+ httpRequestMessage : __httpRequest ,
104+ modelId : modelId ,
105+ anthropicVersion : anthropicVersion ,
106+ xApiKey : xApiKey ) ;
107+
108+ using var __response = await HttpClient . SendAsync (
109+ request : __httpRequest ,
110+ completionOption : global ::System . Net . Http . HttpCompletionOption . ResponseContentRead ,
111+ cancellationToken : cancellationToken ) . ConfigureAwait ( false ) ;
112+
113+ ProcessResponse (
114+ client : HttpClient ,
115+ response : __response ) ;
116+ ProcessBetaModelsGetResponse (
117+ httpClient : HttpClient ,
118+ httpResponseMessage : __response ) ;
119+ // Error response. See our [errors documentation](https://docs.anthropic.com/en/api/errors) for more details.
120+ if ( ( int ) __response . StatusCode >= 400 && ( int ) __response . StatusCode <= 499 )
121+ {
122+ string ? __content_4XX = null ;
123+ global ::Anthropic . BetaErrorResponse ? __value_4XX = null ;
124+ if ( ReadResponseAsString )
125+ {
126+ __content_4XX = await __response . Content . ReadAsStringAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
127+ __value_4XX = global ::Anthropic . BetaErrorResponse . FromJson ( __content_4XX , JsonSerializerContext ) ;
128+ }
129+ else
130+ {
131+ var __contentStream_4XX = await __response . Content . ReadAsStreamAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
132+ __value_4XX = await global ::Anthropic . BetaErrorResponse . FromJsonStreamAsync ( __contentStream_4XX , JsonSerializerContext ) . ConfigureAwait ( false ) ;
133+ }
134+
135+ throw new global ::Anthropic . ApiException < global ::Anthropic . BetaErrorResponse > (
136+ message : __response . ReasonPhrase ?? string . Empty ,
137+ statusCode : __response . StatusCode )
138+ {
139+ ResponseBody = __content_4XX ,
140+ ResponseObject = __value_4XX ,
141+ ResponseHeaders = global ::System . Linq . Enumerable . ToDictionary (
142+ __response . Headers ,
143+ h => h . Key ,
144+ h => h . Value ) ,
145+ } ;
146+ }
147+
148+ if ( ReadResponseAsString )
149+ {
150+ var __content = await __response . Content . ReadAsStringAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
151+
152+ ProcessResponseContent (
153+ client : HttpClient ,
154+ response : __response ,
155+ content : ref __content ) ;
156+ ProcessBetaModelsGetResponseContent (
157+ httpClient : HttpClient ,
158+ httpResponseMessage : __response ,
159+ content : ref __content ) ;
160+
161+ try
162+ {
163+ __response . EnsureSuccessStatusCode ( ) ;
164+ }
165+ catch ( global ::System . Net . Http . HttpRequestException __ex )
166+ {
167+ throw new global ::Anthropic . ApiException (
168+ message : __content ?? __response . ReasonPhrase ?? string . Empty ,
169+ innerException : __ex ,
170+ statusCode : __response . StatusCode )
171+ {
172+ ResponseBody = __content ,
173+ ResponseHeaders = global ::System . Linq . Enumerable . ToDictionary (
174+ __response . Headers ,
175+ h => h . Key ,
176+ h => h . Value ) ,
177+ } ;
178+ }
179+
180+ return
181+ global ::Anthropic . BetaModelResponse . FromJson ( __content , JsonSerializerContext ) ??
182+ throw new global ::System . InvalidOperationException ( $ "Response deserialization failed for \" { __content } \" ") ;
183+ }
184+ else
185+ {
186+ try
187+ {
188+ __response . EnsureSuccessStatusCode ( ) ;
189+ }
190+ catch ( global ::System . Net . Http . HttpRequestException __ex )
191+ {
192+ throw new global ::Anthropic . ApiException (
193+ message : __response . ReasonPhrase ?? string . Empty ,
194+ innerException : __ex ,
195+ statusCode : __response . StatusCode )
196+ {
197+ ResponseHeaders = global ::System . Linq . Enumerable . ToDictionary (
198+ __response . Headers ,
199+ h => h . Key ,
200+ h => h . Value ) ,
201+ } ;
202+ }
203+
204+ using var __content = await __response . Content . ReadAsStreamAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
205+
206+ return
207+ await global ::Anthropic . BetaModelResponse . FromJsonStreamAsync ( __content , JsonSerializerContext ) . ConfigureAwait ( false ) ??
208+ throw new global ::System . InvalidOperationException ( "Response deserialization failed." ) ;
209+ }
210+ }
211+ }
212+ }
0 commit comments