File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import {
22
22
CountTokensRequest ,
23
23
RequestOptions ,
24
24
} from '../types/content' ;
25
+ import { ClientError } from '../types/errors' ;
25
26
import * as constants from '../util/constants' ;
26
27
27
28
/**
@@ -58,13 +59,28 @@ export async function postRequest({
58
59
vertexEndpoint += '?alt=sse' ;
59
60
}
60
61
62
+ if (
63
+ requestOptions ?. apiClient &&
64
+ ( requestOptions ?. apiClient . includes ( '\n' ) ||
65
+ requestOptions ?. apiClient . includes ( '\r' ) )
66
+ ) {
67
+ throw new ClientError (
68
+ 'Found line break in apiClient request option field, please remove ' +
69
+ 'the line break and try again.'
70
+ ) ;
71
+ }
72
+
73
+ const extraHeaders : HeadersInit = requestOptions ?. apiClient
74
+ ? { 'X-Goog-Api-Client' : requestOptions ?. apiClient }
75
+ : { } ;
61
76
return fetch ( vertexEndpoint , {
62
77
...getFetchOptions ( requestOptions ) ,
63
78
method : 'POST' ,
64
79
headers : {
65
80
Authorization : `Bearer ${ token } ` ,
66
81
'Content-Type' : 'application/json' ,
67
82
'User-Agent' : constants . USER_AGENT ,
83
+ ...extraHeaders ,
68
84
} ,
69
85
body : JSON . stringify ( data ) ,
70
86
} ) ;
Original file line number Diff line number Diff line change @@ -890,4 +890,10 @@ export declare interface StartChatSessionRequest extends StartChatParams {
890
890
export interface RequestOptions {
891
891
/** timeout in milli seconds. time out value needs to be non negative. */
892
892
timeout ?: number ;
893
+ /**
894
+ * Value for x-goog-api-client header to set on the API request. This is
895
+ * intended for wrapper SDKs to set additional SDK identifiers for the
896
+ * backend.
897
+ */
898
+ apiClient ?: string ;
893
899
}
You can’t perform that action at this time.
0 commit comments