
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@jnode/gemini
Advanced tools
Simple Gemini API package for Node.js.
npm install @jnode/gemini
const gemini = require('@jnode/gemini');
const client = new gemini.Client('YOUR_API_KEY');
const model = client.model('gemini-pro');
async function generateText() {
const result = await model.generate('Hello');
console.log(result.text);
}
generateText();
GeminiClientThe main class for interacting with the Gemini API.
new gemini.Client(key, options = {})
key: Your Gemini API key.options: An optional object for setting various client options:
apiBase: The base URL of the Gemini API. Default is generativelanguage.googleapis.com.apiThrowError: Whether to throw errors when the API status code is not 2xx. Default is true.fileUnsupportError: Whether to throw errors when the file type is not supported. Default is true.fileActiveCheckDelay: Delay in milliseconds between file status checks. Default is 1500.fileMaxActiveCheck: Maximum number of file status checks. Default is 15.apiUrl(path = '/', query = ''): Returns the full API URL with the base, path, and API key.
path: API endpoint path.query: Query string.string - The full API URL.async apiRequest(method = 'GET', path = '/', query = '', body): Makes an HTTP request to the Gemini API.
method: HTTP method (e.g., GET, POST, PUT, DELETE). Default is GET.path: API endpoint path. Default is /.query: Query string.body: Request body data (will be stringified).Promise<RequestResponse> - A promise that resolves to a RequestResponse object.model(model, options): Returns a GeminiModel instance for interacting with a specific model.
model: The name of the model (e.g., gemini-pro).options: Model options.GeminiModel - A GeminiModel instance.fileManager: An instance of GeminiFileManager for managing files.
GeminiModelRepresents a specific Gemini model.
new gemini.Model(client, model, options = {})
client: A GeminiClient instance.model: The name of the model.options: An optional object for setting model options:
tools: Custom tools to be used by the model.functions: An array of GeminiFunction instances.functionMode: Function calling mode ('NONE', 'AUTO', 'ANY').allowedFunctions: Allowed function names for function calling.safetySettings: Safety settings for the model.systemInstruction: System instruction text.jsonMode: Enable JSON mode (boolean or object with response schema).jsonMode: Enable image generate (boolean).stopSequences: Stop sequences for generation.candidateCount: Number of candidate responses.maxOutputTokens: Maximum number of output tokens.temperature: Temperature for generation.topP: Top-p value for generation.topK: Top-k value for generation.generationConfig: Overwrite the config with original format.imageGenerate: Boolean. Use image generate.optionsToApiFormat(options = {}): Converts simple options to API format.
options: Model options.object - Options in API format.async contentToApiFormat(content): Converts simple content to API format.
content: Content string, array, or object.Promise<array> - Content in API format.apiRequest(method, action, body): Makes an API request for this model.
method: HTTP method.action: API action.body: Request body.Promise<RequestResponse> - A promise that resolves to a RequestResponse object.generate(content, optionsOverwrite = {}): Generates content using the model.
content: Input content, which can be one of the following formats:
'What is the meaning of life?'['What is the capital of France?', 'Paris.', 'And what about Spain?']true which means is a "user" turn) set role to "user" (true) or "model" (false).{ text: string }: A text part.
{ text: 'What is the weather like today?' }{ filePath: string }: A local file to be uploaded and used as input. The file will be automatically uploaded if it hasn't been uploaded already.
{ filePath: './image.png' }{ fileUrl: string }: A web file URL to be used as input. The file will be automatically uploaded if it hasn't been uploaded already.
{ fileUrl: 'https://example.com/image.jpg' }{ file: { mimeType: string, data: Buffer } }: File data directly provided as input.
{ file: { mimeType: 'image/png', data: imageBuffer } }[['What is in this image?', true, { filePath: './image.png' }], false, 'This is a picture of a cat.', ['And this one?', { filePath: './image2.jpg' }]]role and parts properties.
[{ role: 'user', parts: [{ text: 'Hello' }] }, { role: 'model', parts: [{ text: 'Hi there!' }] }]optionsOverwrite: Optional options to overwrite model options.Promise<GeminiContents> - A promise that resolves to a GeminiContents instance.GeminiContentsRepresents the contents generated by a model.
new gemini.Contents(model, contents)
model: A GeminiModel instance.contents: Initial contents array.async generate(content, optionsOverwrite): Generates content and updates the GeminiContents instance.
content: Input content.optionsOverwrite: Optional options to overwrite model options.Promise<this> - The updated GeminiContents instance.async runFunctions(extraData): Executes function calls and continues generation.
extraData: Extra data to be passed to functions.Promise<GeminiContents> - A promise that resolves to a new GeminiContents instance with the function responses.model: The GeminiModel instance.contents: The full contents array.text: The generated text.functionCalls: An array of function calls.usage: Usage metadata.feedback: Prompt feedback.status: Finish reason.attachments: An array of inline data respond by model.GeminiFileManagerManages file uploads and retrieval for the Gemini API.
new gemini.FileManager(client)
client: A GeminiClient instance.async uploadFile(file, isWebFile = false, displayName): Uploads a local or web file to Gemini API.
file: File path or URL.isWebFile: Whether the file is a web file. Default is false.displayName: Optional display name for the file.Promise<object> - A promise that resolves to the uploaded file object.async getFilesList(): Retrieves the list of uploaded files.
Promise<array> - A promise that resolves to an array of file objects.apiDeleteFile(file): Deletes an uploaded file.
file: File name or object.Promise<RequestResponse> - A promise that resolves to a RequestResponse object.async getSmartFile(file, isWebFile = false): Retrieves a file object if it's already uploaded, otherwise returns undefined.
file: File path or URL.isWebFile: Whether the file is a web file.Promise<object|undefined> - A promise that resolves to the file object or undefined.getSmartName(file, isWebFile, mtime): Generates a smart display name for a file.
file: File path or URL.isWebFile: Whether the file is a web file.mtime: File modification time.string - The smart display name.client: The GeminiClient instance.filesCache: An array of cached file objects.GeminiFunctionRepresents a function that can be called by the Gemini model.
new gemini.Function(name, description, parameters = null, func)
name: Function name.description: Function description.parameters: Function parameters (in OpenAPI format).func: The actual function to be executed.toApiFormat(): Converts the GeminiFunction instance to API format.
object - Function in API format.GeminiAPIErrorAn error that is thrown when the Gemini API returns a non-2xx status code.
new GeminiAPIError(code, body, headers)
code: The error code.body: The response body.headers: The response headers.message: The error message.code: The error code.body: The response body.headers: The response headers.RequestResponse class with properties like:
code: Status code.headers: Response headers.text(encoding): Return response body in string, with optional encoding. Example: res.text('utf-8').json(): Return response body in JSON format, or undefined when cannot parse JSON. Example: res.json().supportMimeTypes: An object mapping file extensions to MIME types.FAQs
Simple Gemini API package for Node.js.
We found that @jnode/gemini demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.