import {createPromiseClient, Interceptor} from"@connectrpc/connect";import { createConnectTransport } from"@connectrpc/connect-node";import { APIGatewayService} from"@buf/fxnlabs_api-gateway.connectrpc_es/apigateway/v1/apigateway_connect.js";functioncreateAPIClient() {// Adds API Key to each requestconstapiKeyInterceptor:Interceptor= (next) =>async (req) => {req.header.set("x-api-key",process.env.FXN_API_KEY!)returnawaitnext(req); };// Creates the transportconsttransport=createConnectTransport({ httpVersion:"1.1", baseUrl:"api.function.network", interceptors: [apiKeyInterceptor] });// Creates the clientreturncreatePromiseClient(APIGatewayService, transport);}
Step 4: Call our API services
// Init the API ClientconstapiClient=createAPIClient()// Use API Clientconstresponse=awaitapiClient.embed({ model:"bge-small-en-v1.5", input:"Embed me so I can use it for RAG Pipelines",})// Log responsesconsole.log(response.object)console.log(response.data)