{"id":14959637,"url":"https://github.com/kilkelly/nanogptjs","last_synced_at":"2025-10-23T02:42:14.833Z","repository":{"id":254289473,"uuid":"844537316","full_name":"kilkelly/nanogptjs","owner":"kilkelly","description":"Interact with NanoGPT's API for pay-per-prompt interaction with AI models","archived":false,"fork":false,"pushed_at":"2025-01-03T13:20:47.000Z","size":39,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-31T03:31:42.736Z","etag":null,"topics":["ai","chatgpt","claude","dall-e","flux","gemini","gpt","llama","llm","nano","nanocurrency","nanogpt","stablediffusion"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kilkelly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-19T13:12:14.000Z","updated_at":"2025-01-26T01:16:28.000Z","dependencies_parsed_at":"2024-12-16T19:45:51.951Z","dependency_job_id":"4478318d-8598-444a-a332-abf8ee8332ef","html_url":"https://github.com/kilkelly/nanogptjs","commit_stats":{"total_commits":14,"total_committers":2,"mean_commits":7.0,"dds":0.0714285714285714,"last_synced_commit":"0e90e44e1b20c3b65fdaf864ddf8e0c7d15fd408"},"previous_names":["kilkelly/nanogptjs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kilkelly%2Fnanogptjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kilkelly%2Fnanogptjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kilkelly%2Fnanogptjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kilkelly%2Fnanogptjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kilkelly","download_url":"https://codeload.github.com/kilkelly/nanogptjs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238008516,"owners_count":19401266,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","chatgpt","claude","dall-e","flux","gemini","gpt","llama","llm","nano","nanocurrency","nanogpt","stablediffusion"],"created_at":"2024-09-24T13:20:18.273Z","updated_at":"2025-10-23T02:42:14.752Z","avatar_url":"https://github.com/kilkelly.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NanoGPTJS\n\nNode.js library to Interact with [NanoGPT](https://nano-gpt.com/)'s API. The NanoGPT service enables pay-per-prompt interaction with chat and image generation models. You will need a prefilled NanoGPT wallet and [API key](https://nano-gpt.com/settings) to use this library effectively.\n\n## Installation\n```sh\nnpm install --save nanogptjs\n```\n\n## Sample Usage\n\n```js\nconst nanogptjs = require('nanogptjs')\nconst { YOUR_NANO_GPT_API_KEY } = require('./secrets.js')\n\n;(async function () {\n\n   const nanogpt = nanogptjs({\n    apiKey: YOUR_NANO_GPT_API_KEY,\n    defaultModel: 'chatgpt-4o-latest'\n  })\n\n  let { reply } = await nanogpt.chat('Tell me something about Nano digital currency?')  \n\n  console.log(reply) // Nano is a feeless and instant cryptocurrency.\n})()\n\n```\n\n## Setup\n\nImporting `nanogptjs`\n```js\nconst nanogptjs = require('nanogptjs')\n```\n\nCreate a `nanogptjs` instance with your NanoGPT API key (required)\n```js\nconst nanogpt = nanogptjs({\n  apiKey: YOUR_NANO_GPT_API_KEY\n})\n```\n\nAlternatively supply a `defaultModel` to be used in further function calls\n```js\nconst nanogpt = nanogptjs({\n  apiKey: YOUR_NANO_GPT_API_KEY,\n  defaultModel: 'chatgpt-4o-latest'\n})\n```\n\n## API\n\n### chat(String prompt)\n\nSends a chat prompt. Requires `defaultModel` field be set when creating your `nanogptjs` instance.\n\n```js\nlet reply = await nanogpt.chat('Tell me something about Nano digital currency?')\n```\n\n#### Arguments\n\n- **prompt** (String, required) - This is the prompt that will be sent to the text model.\n\nReturns a Promise that resolves to an Object with the following format:\n```js\n{\n  reply: \"Nano is a feeless and instant cryptocurrency.\", // the reply to your chat prompt\n  metadata: {\n    cost: 0.001089, // cost of this interaction\n    paymentSource: 'XNO', // currency used for payment\n    inputTokens: 24, // number of tokens your input created\n    outputTokens: 21 // number of tokens your output created\n  }\n}\n```\n\n### chat(Object config)\n\nSends a chat prompt. Gives you more control by allowing you to specify model and chat context (i.e. history).\n\n```js\nlet reply = await nanogpt.chat({\n  prompt: 'What is my favorite color?', // chat prompt\n  model: 'chatgpt-4o-latest', // model to use\n  context: [\n    nanogpt.contextUser('Blue is my favorite color'),\n    nanogpt.contextAI('Very interesting! I will remember that.'),\n  ] // context for your chat prompt\n})\n```\n\n#### Arguments\n\n- **config** (Object, required)) - This is a configuration Object containing the following fields: \n  - **prompt** (String, required) - This is the prompt that will be sent to the text model.\n  - **model** (String, optional) - The text model to use. This field is optional if the `defaultModel` field is set when creating your `nanogptjs` instance.\n  - **context** (Array, optional) - Provide context (chat history) to your chat prompt. Send context in an alternating user-to-AI sequence. Use the utility functions `contextUser` and `contextAI` to specify who is speaking.\n\nReturns a Promise that resolves to an Object with the following format:\n```js\n{\n  reply: \"Based on prior informations, I think blue is your favorite color!\", // the reply to your chat prompt\n  metadata: {\n    cost: 0.001089, // cost of this interaction\n    paymentSource: 'XNO', // currency used for payment\n    inputTokens: 24, // number of tokens your input created\n    outputTokens: 21 // number of tokens your output created\n  }\n}\n```\n\n### image(Object config)\n\nGenerates a single image.\n\n```js\nlet image = await nanogpt.image({\n  prompt: 'a beautiful landscape, bright sunshine, green fields',\n  model: 'dreamshaper_8_93211.safetensors',\n  width: 1024,\n  height: 1024\n})\n```\n\n#### Arguments\n\n- **config** (Object, required) - This is a configuration Object containing the following fields: \n  - **prompt** (String, required) - This is the prompt for what you want to see in your generated image.\n  - **width** (Integer, optional) - The width of the image you want to generate.\n  - **height** (Integer, optional) - The height of the image you want to generate.\n  - **negativePrompt** (String, optional) - This is the prompt for what you **don't** want to see in your generated image.\n  - **steps** (Integer, optional) - Number of generation steps. Higher is better but more expensive. Aim for 25-30.\n  - **sampler** (String, optional) - Sampler that will be used to denoise your image during generation. For advanced users.\n  - **scale** (Number, optional) - Determines how much the image generation process follows the text prompt. For advanced users.\n\nReturns a Promise that resolves to an Object with the following format:\n```js\n{\n  base64: \" /9j/4AAQSkZJRgABAQAAAQABAAD...\", // base64 encoded version of your generated image\n  metadata: {\n    created: 1723814389930, // timestamp of this image generation\n    cost: 0.0021, // cost of this interaction\n    paymentSource: 'XNO' // currency used for payment\n  }\n}\n```\n\n### imageBatch(Object config)\n\nGenerates a specific number of  images.\n\n```js\nlet imageBatch = await nanogpt.imageBatch({\n  batchSize: 2,\n  prompt: 'a beautiful landscape with a large cat',\n  model: 'dreamshaper_8_93211.safetensors',\n  width: 1024,\n  height: 1024\n})\n```\n\n#### Arguments\n\n- **config** (Object, required) - This is a configuration Object containing the following fields: \n  - **batchSize** (Number, required) - Specify how many images to generate. The more images, the higher the Nano cost.\n  - **prompt** (String, required) - This is the prompt for what you want to see in your generated image.\n  - **width** (Integer, optional) - The width of the image you want to generate.\n  - **height** (Integer, optional) - The height of the image you want to generate.\n  - **negativePrompt** (String, optional) - This is the prompt for what you **don't** want to see in your generated image.\n  - **steps** (Integer, optional) - Number of generation steps. Higher is better but more expensive. Aim for 25-30.\n  - **sampler** (String, optional) - Sampler that will be used to denoise your image during generation. For advanced users.\n  - **scale** (Number, optional) - Determines how much the image generation process follows the text prompt. For advanced users\n\n#### Returns\n\nReturns a Promise that resolves to an Object with the following format:\n```js\n{\n  imageBatch: [ // array of generated images\n    base64: \" /9j/4AAQSkZJRgABAQAAAQAQAQA...\", // base64 encoded version of your generated image\n    base64: \" /9j/4AAQSkZJRgABAQAAAQAABAB...\", // base64 encoded version of your generated image  \n  ]\n  metadata: {\n    created: 1723815073228, // timestamp of this image generation\n    cost: 0.00501, // cost of this interaction\n    paymentSource: 'XNO' // currency used for payment\n  }\n}\n```\n\n### account()\n\nRetrieves information about your NanoGPT account.\n\n```js\nlet account = await nanogpt.account()\n```\n\nReturns a Promise that resolves to an Object with the following format:\n```js\n{\n  nanoDepositAddress: 'nano_3d46mow3fim7bfd15xckfgao9ehabmp56y7gkn9q3nky1i3buehtroxi8q67',\n  nanoReturnAddress: 'nano_15qzsidyztg1i7at4zdeapzzh5hfgy1rip8e5uz1an3tujuunujgesgzf187',\n  balance: 3.098908,\n  receivable: 0,\n  earned: '0.000000'\n}\n```\n\n### balance()\n\nRetrieves your current NanoGPT account balance.\n\n```js\nlet balance = await nanogpt.balance()\n```\n\nReturns a Number\n```js\n4.0678\n```\n\n### models()\n\nRetrieves information about the models available on NanoGPT.\n\n```js\nlet models = await nanogpt.models()\n```\n\nReturns a Promise that resolves to an Object with the following format:\n```js\n{\n  \"models\": {\n    \"text\": {\n      \"gpt-4o\": {\n        \"name\": \"GPT 4o\",\n        \"model\": \"gpt-4o\",\n        \"description\": \"OpenAI's most advanced model. It matches GPT-4 Turbo performance on text in English and code, with significant improvement on text in non-English languages, while also being much faster and 50% cheaper.\",\n        \"cost\": \"Average cost: 0.025 Nano\",\n        \"costEstimate\": 0.025,\n        \"labelVariant\": \"outline\",\n        \"label\": \"Recommended\",\n        \"visible\": false\n      },\n      // ...more text models\n    },\n    \"image\": {\n      \"dall-e-3\": {\n        \"name\": \"DALL-E-3\",\n        \"model\": \"dall-e-3\",\n        \"engine\": \"dalle\",\n        \"description\": \"The current golden standard in image generation.\",\n        \"cost\": {\n          \"1024x1024\": 0.04,\n          \"1024x1792\": 0.08,\n          \"1792x1024\": 0.08\n        },\n        \"label\": \"Default\",\n        \"maxImages\": 1,\n        \"resolutions\": [\n          {\n            \"value\": \"1024x1024\"\n          },\n          {\n            \"value\": \"1024x1792\",\n            \"comment\": \"2x the price\"\n          },\n          {\n            \"value\": \"1792x1024\",\n            \"comment\": \"2x the price\"\n          }\n        ]\n      },\n      // ...more image models\n    }\n  }\n}\n```\n\n### contextUser(String content)\n\nUtility function to aid with creation of the Object field `context` in the `chat` function.\n\n```js\nnanogpt.contextUser('Blue is my favorite color')\n```\n\n#### Arguments\n\n- **content** (String, required) - Content that the user previously supplied via chat prompt.\n\nReturns an Object with the following format:\n```js\n{\n  role: 'user',\n  content: 'Blue is my favorite color'\n}\n```\n\n### contextAI(String content)\n\nUtility function to aid with creation of the Object field `context` in the `chat` function. \n\n```js\nnanogpt.contextAI('Very interesting! I will remember that.')\n```\n\n#### Arguments\n\n- **content** (String, required) - Content that the AI previously replied with.\n\nReturns an Object with the following format:\n```js\n{\n  role: 'assistant',\n  content: 'Very interesting! I will remember that.'\n}\n```\n\n## Examples\n\nYou can find multiple NanoGPTJS usage examples in the [examples](https://github.com/kilkelly/nanogptjs/tree/main/examples) folder.\n\n## Feedback\n\nPull requests and opened issues are welcome!\n\n## Disclaimer\n\nAs always when working with real world value, in this case Nano, be careful when using this library. The authors and contributors shall not be held liable for any use of this library's functionality, intentional or unintentional, that leads to an undesired lose of funds.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkilkelly%2Fnanogptjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkilkelly%2Fnanogptjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkilkelly%2Fnanogptjs/lists"}