@@ -19,7 +19,8 @@ export interface RunOptions {
1919 threadId ?: string ;
2020 rawResponse ?: boolean ;
2121 runTools ?: boolean ;
22- name ?: string ; // Pipe name for SDK
22+ name ?: string ; // Pipe name for SDK,
23+ apiKey ?: string ; // pipe level key for SDK
2324}
2425
2526export interface RunOptionsStream extends RunOptions {
@@ -83,12 +84,16 @@ export class Pipe {
8384 private maxCalls : number ;
8485 private hasTools : boolean ;
8586 private prod : boolean ;
87+ private baseUrl : string ;
8688
8789 constructor ( options : PipeOptions ) {
8890 this . prod = options . prod ?? isProd ( ) ;
89- const baseUrl = getApiUrl ( this . prod ) ;
91+ this . baseUrl = getApiUrl ( this . prod ) ;
9092
91- this . request = new Request ( { apiKey : options . apiKey , baseUrl} ) ;
93+ this . request = new Request ( {
94+ apiKey : options . apiKey ,
95+ baseUrl : this . baseUrl ,
96+ } ) ;
9297 this . pipe = options ;
9398
9499 delete this . pipe . prod ;
@@ -163,7 +168,6 @@ export class Pipe {
163168 private async handleStreamResponse (
164169 options : RunOptionsStream ,
165170 response : RunResponseStream ,
166- pipeName : string ,
167171 ) : Promise < RunResponseStream > {
168172 const endpoint = '/v1/pipes/run' ;
169173 const stream = this . isStreamRequested ( options ) ;
@@ -218,7 +222,6 @@ export class Pipe {
218222 messages,
219223 threadId : currentResponse . threadId ,
220224 } ,
221- pipeName
222225 ) ;
223226
224227 callCount ++ ;
@@ -247,7 +250,21 @@ export class Pipe {
247250 const modelProvider = getProvider ( providerString ) ;
248251 const isAnthropic = modelProvider === ANTHROPIC ;
249252 const hasTools = this . pipe . tools . length > 0 ;
250- const pipeName = options . name || this . pipe . name ;
253+
254+ // For SDK
255+ // Run the given pipe name
256+ if ( options . name ) {
257+ this . pipe = { ...this . pipe , name : options . name } ;
258+ }
259+
260+ // For SDK
261+ // Run the pipe against the given Pipe API key
262+ if ( options . apiKey ) {
263+ this . request = new Request ( {
264+ apiKey : options . apiKey ,
265+ baseUrl : this . baseUrl ,
266+ } ) ;
267+ }
251268
252269 let stream = this . isStreamRequested ( options ) ;
253270
@@ -264,7 +281,7 @@ export class Pipe {
264281
265282 let response = await this . createRequest <
266283 RunResponse | RunResponseStream
267- > ( endpoint , body , pipeName ) ;
284+ > ( endpoint , body ) ;
268285 if ( Object . entries ( response ) . length === 0 ) {
269286 return { } as RunResponse | RunResponseStream ;
270287 }
@@ -281,7 +298,6 @@ export class Pipe {
281298 return await this . handleStreamResponse (
282299 options as RunOptionsStream ,
283300 response as RunResponseStream ,
284- pipeName
285301 ) ;
286302 }
287303
@@ -324,7 +340,7 @@ export class Pipe {
324340 messages,
325341 stream : false ,
326342 threadId : currentResponse . threadId ,
327- } , pipeName ) ;
343+ } ) ;
328344
329345 callCount ++ ;
330346
@@ -343,17 +359,13 @@ export class Pipe {
343359 return currentResponse ;
344360 }
345361
346- private async createRequest < T > (
347- endpoint : string ,
348- body : any ,
349- pipeName ?: string ,
350- ) : Promise < T > {
362+ private async createRequest < T > ( endpoint : string , body : any ) : Promise < T > {
351363 const isProdEnv = this . prod ;
352364 const prodOptions = {
353365 endpoint,
354366 body : {
355367 ...body ,
356- name : pipeName || this . pipe . name ,
368+ name : this . pipe . name ,
357369 } ,
358370 } ;
359371
0 commit comments