https://github.com/Gimer-Studios/APIMyLlama
API up your Ollama Server.
https://github.com/Gimer-Studios/APIMyLlama
ai easy-to-use ollama ollama-api open-source
Last synced: 11 days ago
JSON representation
API up your Ollama Server.
- Host: GitHub
- URL: https://github.com/Gimer-Studios/APIMyLlama
- Owner: Gimer-Studios
- License: mit
- Created: 2024-05-27T12:30:14.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-09T15:56:58.000Z (4 months ago)
- Last Synced: 2025-09-23T04:38:33.815Z (16 days ago)
- Topics: ai, easy-to-use, ollama, ollama-api, open-source
- Language: JavaScript
- Homepage:
- Size: 6.31 MB
- Stars: 179
- Watchers: 5
- Forks: 40
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: License.txt
Awesome Lists containing this project
README
# APIMyLlama V2 Documentation
## Overview
[](https://www.youtube.com/embed/x_MSmGX3Vmc)
APIMyLlama is a server application that provides an interface to interact with the Ollama API, a powerful AI tool to run LLMs. It allows users to run this alongside Ollama to easily distrubute API keys to create amazing things.
### Support Us
We now have a [Ko-fi](https://ko-fi.com/gimerstudios) open if you would like to help and donate to the project. We love to keep it free and open source when possible and donating helps a lot.
[Donate through Ko-fi](https://ko-fi.com/gimerstudios)
# Installation
## Ollama Setup
If you already have Ollama setup with the 'ollama serve' command and your desired model. You can skip this. If not i'll show you how to set it up. First install [Ollama](https://ollama.com/download) for your desired operating system. Once installed open a terminal instance and run the command below.
```bash
ollama pull llama3
```If done correctly you should now have the Meta's Llama3 LLM installed. You can use any model with the API but for this example we will use this model. Now you are gonna run this command after the install is complete.
```bash
ollama serve
```
Now you have an Ollama server setup. Time for the next step.## Hosting the API
Install [Node.JS](https://nodejs.org/en/download/package-manager) on your server. Then clone the git repository.
```bash
git clone https://github.com/Gimer-Studios/APIMyLlama.git
cd APIMyLlama
npm install
node APIMyLlama.js
```
After cloning go into the APIMyLlama directory and install all the needed dependencies by running the 'npm install' command. Then run the APIMyLlama.js file.
On startup it will ask what port you want to use.
```
PS C:\Users\EXAMPLE\Documents\APIMyLlama> node APIMyLlama.js
APIMyLlama V2 is being started. Thanks for choosing Gimer Studios.
Connected to the apiKeys.db database.
Enter the port number for the API server: 3000
Port number saved to port.conf: 3000
Enter the URL for the Ollama server (URL that your Ollama server is running on. By default it is "http://localhost:11434" so if you didnt change anything it should be that.): :11434'. If you changed the port then you can put your port here instead of '11434'. This last thing applies to running Ollama and APIMyLlama on 2 different systems. If you are doing this. You will NEED to run Ollama to listen on ALL interfaces. You can do this on Windows or Linux like shown below.## Let Ollama Listen on all interfaces (Only applies if you are using 2 different systems for the APIMyLlama server and Ollama.)
Windows:
For Windows you can set a System Environment Variable. The variable and the value are listed below.
```
Variable: OLLAMA_HOST
Value: 0.0.0.0
```
Linux:
For Linux you can edit the service file for Ollama. Open /etc/systemd/system/ollama.service and add the following line inside the [Service] section
```
Environment="OLLAMA_HOST=0.0.0.0"
```
On Linux you can also just run the command below to listen on all interfaces if that is easier for you. However you will need to run Ollama with this command everytime you start it up if you want to use APIMyLlama.
```
OLLAMA_HOST=0.0.0.0 ollama serve
```## Commands
These are the commands you can use in the APIMyLlama application```bash
generatekey
```
This command will generate a key using Cryptography and save it to the local database.```bash
listkey
```
This command will list all API Keys in the database.```bash
removekey
```
This command will remove any key from the database.```bash
addkey
```
You can add custom keys if wanted. (DO with CAUTION as it may be unsafe)```bash
changeport
```
You can change the servers port in realtime without having to restart the application.```bash
changeollamaurl
```
You can change the Ollama Server url if you have a custom one set. By default it is "http://localhost:11434".```bash
addwebhook
```
You can add webhooks for alerts when a new request is made. EX. Discord Webhook```bash
listwebhooks
```
This command will list all the webhooks you have attached to your system.```bash
deletewebhook
```
This command can be used to remove a webhook in your system. You can get the ID of the webhook using the 'listwebhooks' command.```bash
ratelimit
```
This command allows you to change the ratelimit on a key. By default it is 10. The rate limit is by minute. So for example the default allows 10 requests to the API per minute.```bash
deactivatekey
```
Allows you to deactivate an API key. This will make the key useless untill it is activated.```bash
activatekey
```
Activates a API key that has been deactivated in the past.```bash
addkeydescription
```
This command lets you add a description to a key to help you decipher what key does what.```bash
listkeydescription
```
This command lists the description of that key if it has a description.```bash
generatekeys
```
Quickly generate multiple new API keys.```bash
regeneratekey
```
Regenerate any specified API key without affecting other details.```bash
activateallkeys
```
Activate all your API keys with a single command.```bash
deactivateallkeys
```
Deactivate all your API keys with a single command.```bash
getkeyinfo
```
Retrieve detailed information about a specific API key.```bash
listactivekeys
```
Easily list all active API keys.```bash
listinactivekeys
```
Easily list all inactive API keys.## Working with the API
Install APIMyLlama packages with NPM (Node.JS), PIP (Python), Jitpack Repo+Gradle or Maven (Java), or from the Crates Repository (Rust)NPM Install (Node.JS)
```bash
cd PROJECT_NAME
npm install apimyllama-node-package
```
PIP Install (Python)
```bash
cd PROJECT_NAME
pip install apimyllama
```
Jitpack+Gradle Repository (Java IF YOUR USING GRADLE)
```bash
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://www.jitpack.io' }
}
}
```Jitpack+Gradle Dependency (Java IF YOUR USING GRADLE)
```bash
dependencies {
implementation 'com.github.Gimer-Studios:APIMyLlama-Java-Package:V2.0.5'
}
```Jitpack+Maven Repository (Java IF YOUR USING MAVEN)
```bash
jitpack.io
https://www.jitpack.io
```Jitpack+Maven Dependency (Java IF YOUR USING MAVEN)
```bash
com.github.Gimer-Studios
APIMyLlama-Java-Package
V2.0.5
```
Crate Repository (Rust)
```bash
[dependencies]
apimyllama = "2.0.7"
tokio = { version = "1", features = ["full"] }
```# Examples to get response from API
Node.JS example:
```bash
const apiMyLlamaNodePackage = require('apimyllama-node-package');// Intialize Parameters
const apikey = 'API_KEY';
const prompt = 'Hello!';
const model = 'llama3';
const ip = 'SERVER_IP';
const port = 'SERVER_PORT';
const stream = false;apiMyLlamaNodePackage.generate(apikey, prompt, model, ip, port, stream)
.then(response => console.log(response))
.catch(error => console.error(error));
```Python example:
```bash
import requests
from apimyllama import ApiMyLlamadef main():
ip = "SERVER_IP"
port = "PORT_NUMBER"
apikey = "API_KEY"
prompt = "Hello"
model = "llama3"
api = ApiMyLlama(ip, port)
try:
result = api.generate(apikey, prompt, model)
print("API Response:", result)
except requests.RequestException as e:
print("An error occurred:", e)if __name__ == "__main__":
main()
```Java Example:
```bash
import com.gimerstudios.apimyllama.ApiMyLlama;
import java.io.IOException;public class TestAPIMyLlama {
public static void main(String[] args) {
String serverIp = "SERVER_IP";
int serverPort = SERVER_PORT;
String apiKey = "API_KEY";
String prompt = "Hello!";
String model = "llama3";
boolean stream = false;ApiMyLlama apiMyLlama = new ApiMyLlama(serverIp, serverPort);
try {
String response = apiMyLlama.generate(apiKey, prompt, model, stream);
System.out.println("Generate Response: " + response);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
```Rust Example:
```bash
use apimyllama::ApiMyLlama;
use std::error::Error;#[tokio::main]
async fn main() -> Result<(), Box> {
let server_ip = "127.0.0.1".to_string();
let server_port = 3000;
let api_key = "api";
let api = ApiMyLlama::new(server_ip, server_port);
let prompt = "Hello!";
let model = "llama3";match api.generate(api_key, prompt, model, false).await {
Ok(response) => {
println!("Response: {}", response.response);
println!("Model: {}", response.model);
println!("Created At: {}", response.created_at);
println!("Done: {}", response.done);
println!("Done Reason: {}", response.done_reason);
println!("Context: {:?}", response.context);
println!("Total Duration: {}", response.total_duration);
println!("Load Duration: {}", response.load_duration);
println!("Prompt Eval Duration: {}", response.prompt_eval_duration);
println!("Eval Count: {}", response.eval_count);
println!("Eval Duration: {}", response.eval_duration);
}
Err(e) => println!("Text generation failed: {}", e),
}Ok(())
}
```## Checking API Health
The packages have built in health checking command (AS OF V2)
If you already have the Node.js or Python packages installed then you can just copy and paste the code below to test.Node.JS example:
```bash
const apiMyLlamaNodePackage = require('apimyllama-node-package');// Intialize Parameters
const apikey = 'API_KEY';
const ip = 'SERVER_IP';
const port = 'SERVER_PORT';apiMyLlamaNodePackage.getHealth(apikey, ip, port)
.then(response => console.log('Health Check Response:', response))
.catch(error => console.error('Error:', error));
```Python example:
```bash
import requests
from apimyllama import ApiMyLlamaip = 'YOUR_SERVER_IP'
port = 'YOUR_SERVER_PORT'
apikey = 'YOUR_API_KEY'api = ApiMyLlama(ip, port)
try:
health = api.get_health(apikey)
print("Health Check Response:", health)
except requests.RequestException as error:
print("Error:", error)
```Java example:
```bash
import com.gimerstudios.apimyllama.ApiMyLlama;
import java.io.IOException;
import java.util.Map;public class TestAPIMyLlama {
public static void main(String[] args) {
String serverIp = "SERVER_IP";
int serverPort = SERVER_PORT;
String apiKey = "API_KEY";ApiMyLlama apiMyLlama = new ApiMyLlama(serverIp, serverPort);
try {
Map healthStatus = apiMyLlama.getHealth(apiKey);
System.out.println("Health Status: " + healthStatus);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
```Rust Example:
```bash
use apimyllama::ApiMyLlama;
use std::error::Error;#[tokio::main]
async fn main() -> Result<(), Box> {
let server_ip = "127.0.0.1".to_string();
let server_port = 3000;
let api_key = "api";
let api = ApiMyLlama::new(server_ip, server_port);match api.get_health(api_key).await {
Ok(response) => {
println!("API Health Status: {}", response.status);
println!("Timestamp: {}", response.timestamp);
}
Err(e) => println!("Health check failed: {}", e),
}Ok(())
}
```## API References
```
ApiMyLlama(ip, port)
ip: IP address of the APIMyLlama server.
port: Port number on which the APIMyLlama server is running.
```
```
api.generate(apiKey, prompt, model, stream)
api.get_health(apikey)
apiKey: API key for accessing the Ollama API.
prompt: Text prompt to generate a response.
model: Machine learning model to use for text generation.
stream: Boolean indicating whether to stream the response.
```
# Support
If there are any issues please make a Github Issue Report. To get quicker support join our discord server.
-[Discord Server](https://discord.gg/r6XazGtKg7) If there are any feature requests you may request them in the discord server. PLEASE NOTE this project is still in EARLY BETA.### Support Us
We now have a [Ko-fi](https://ko-fi.com/gimerstudios) open if you would like to help and donate to the project. We love to keep it free and open source when possible and donating helps a lot.
[Donate through Ko-fi](https://ko-fi.com/gimerstudios)
## FAQ
#### 1. Why am I getting the module not found error?
You most likely forgot to run the 'npm install' command after cloning the repository.
#### 2. Why can't I use the API outside my network?
You probably didn't port foward. And if you did your router may have not intialized the changes yet or applied them.
#### 3. Ollama Serve command error "Error: listen tcp 127.0.0.1:11434: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted."
If you get this error just close the Ollama app through the system tray on Windows. And if your on Linux just use systemctl to stop the Ollama process. Once done you can try running the ollama serve command again.
#### 4. error: 'Error making request to Ollama API'
If you have a custom port set for your Ollama server this is a simple fix. Just run the 'changeollamaurl ' and change it to the url your Ollama server is running on. By default it is "http://localhost:11434" but if you changed it you will need to do this. You can also fix this problem through changing the port in the ollamaURL.conf file.
## Authors
- [@gimerstudios](https://github.com/Gimer-Studios)