generic LLM call
This is an as-is Python AWS-compatible Lambda OpenAI-specification call that you can use anywhere else or even for a non-AI app such as a reminder or To-Do app. It is just a post-response (signal-echo) system where anything or a set of a bunch of whatever can be the remote back-end. This stack relies on API Gateway for auth. It can be configured with a zero-trust or full-retention modality, depending on data needs. All calls are assumed to consist of a REST "ticket" 🎫 containing a binary encoded message. It can be run serverless or dedicated or local or cloud. License keys are on you.
It can also interface with anything using generic REST calls such as:
curl -v -X POST \
'https://LAMBDA_ENDPOINT.us-east-2.<CLOUDHOST>.com/v1/<?HOOK>' \
-H 'content-type: application/json' \
-H 'Authorization: <token>' \
-d '{"body": "{"id": 152948599,"version_id": 1856687097,"text": "bWFya2V0IGVudHJ5IGZvciBFdXJvcGVhbiBkYWlyeSBwcm9kdWNlciBpbiBVQUU=","timestamp": "1702307960","sender": "user","metadata": {"conversationTopic": "TmV3IENoYXQ=","tool": ["Y2hhdGJvdA==","aW5zdHJ1Y3Rpb24=","dG9uZQ==","bGVuZ3Ro"],"reference": ["Z3B0My41LXR1cmJv","cHJvZmVzc2lvbmFs","cHJvZmVzc2lvbmFs","c2hvcnQ="],"token_cost": 2138,"rating": 1}}"}'
RESTFul API calls live in NP-Space whereas the stream once locked-in, will run in Linear (P-Time)
This does not mean they are secure, only that the schematic takes a long time to crack open, whereas encoding makes the system expensive to crack, and encryption makes the system hazardouse to crack due to the unknown payload. anything once it leaves the sender (your machine) should be assumed to be tampered with, which is what LLMs do: modify a signal and bounce it back. POST requests are used to send data to a server to create or update a resource. Unlike GET requests, which retrieve data, POST requests submit data for processing. POST requests are not idempotent, meaning sending the same request multiple times can lead to multiple records being created.
POST /api/v1/setlattice HTTP/1.1 Host: <REMOTE_URI> Content-Type: application/json
{ "name": "Set Cover Lettuce Product", "price": 29.99, "description": "A brand new product from set" }
Unlike POST requests, which can create new resources, PUT requests are meant for replacing or updating the data of an already existing resource. When a PUT request is sent, it instructs the server to overwrite the existing resource with the new data provided.
This is for when you want to change Key-Value storage such as memory in a dataplane or modify an in-flight engram in a virtual machine
Another useful RESTFul API Schema is the Stripe Schema for Payment:
curl https://api.<PAYMENT_RAIL_URI?.#com/v1/customers \
-u "sk_test_bc1q63llmqp5umkzrgpumjfudh6fwgyf97c46ngc9f:" \
-d "name=Kim Kardasheva Net Yaroze Roze" \
--data-urlencode "email=kimkardashian@utexas.edu"
So instead of an /etc/defaults file with your sk_test key, if you have an HTTP proxy managing secrets you can do this:
curl https://api.<PAYMENT_RAIL_URI?.#com/v1/customers \
-d "name=Satoshi Nakamoto" \
--data-urlencode "email=kimkardashian@utexas.edu"
@JavaScript [ECMA 2.0]
// Encode (UTF-8 string → Base64)
function encodeBase64(str) {
return typeof window === "undefined"
? Buffer.from(str, "utf-8").toString("base64") // Node
: btoa(unescape(encodeURIComponent(str))); // Browser-safe
}
// Decode (Base64 → UTF-8 string)
function decodeBase64(b64) {
return typeof window === "undefined"
? Buffer.from(b64, "base64").toString("utf-8") // Node
: decodeURIComponent(escape(atob(b64))); // Browser-safe
}
const url = "https://LAMBDA_ENDPOINT.us-east-2.<CLOUDHOST>.com/v1/<?HOOK>";
const payload = {
body: {
id: 152948599,
version_id: 1856687097,
text: "bWFya2V0IGVudHJ5IGZvciBFdXJvcGVhbiBkYWlyeSBwcm9kdWNlciBpbiBVQUU=",
timestamp: "1702307960",
sender: "user",
metadata: {
conversationTopic: "TmV3IENoYXQ=",
tool: ["Y2hhdGJvdA==", "aW5zdHJ1Y3Rpb24=", "dG9uZQ==", "bGVuZ3Ro"],
reference: ["Z3B0My41LXR1cmJv", "cHJvZmVzc2lvbmFs", "cHJvZmVzc2lvbmFs", "c2hvcnQ="],
token_cost: 2138,
rating: 1
}
}
};
const res = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "<token>"
},
body: JSON.stringify(payload)
});
const data = await res.json();
console.log(data);
@XNU-Like BSD Distributuons [Async/Await Swift 4.0]
import Foundation
func encodeBase64(_ string: String) -> String? {
return string.data(using: .utf8)?.base64EncodedString()
}
func decodeBase64(_ base64: String) -> String? {
guard let data = Data(base64Encoded: base64) else { return nil }
return String(data: data, encoding: .utf8)
}
let url = URL(string: "https://LAMBDA_ENDPOINT.us-east-2.<CLOUDHOST>.com/v1/<?HOOK>")!
let payload: [String: Any] = [
"body": [
"id": 152948599,
"version_id": 1856687097,
"text": "bWFya2V0IGVudHJ5IGZvciBFdXJvcGVhbiBkYWlyeSBwcm9kdWNlciBpbiBVQUU=",
"timestamp": "1702307960",
"sender": "user",
"metadata": [
"conversationTopic": "TmV3IENoYXQ=",
"tool": ["Y2hhdGJvdA==","aW5zdHJ1Y3Rpb24=","dG9uZQ==","bGVuZ3Ro"],
"reference": ["Z3B0My41LXR1cmJv","cHJvZmVzc2lvbmFs","cHJvZmVzc2lvbmFs","c2hvcnQ="],
"token_cost": 2138,
"rating": 1
]
]
]
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("<token>", forHTTPHeaderField: "Authorization")
request.httpBody = try JSONSerialization.data(withJSONObject: payload)
let (data, _) = try await URLSession.shared.data(for: request)
print(String(data: data, encoding: .utf8)!)
@Rust (reqwest + serde idioms) add to Cargo.toml base64 = "0.22"
use reqwest::Client;
use serde::Serialize;
#[derive(Serialize)]
struct Metadata {
conversationTopic: String,
tool: Vec<String>,
reference: Vec<String>,
token_cost: u32,
rating: u8,
}
#[derive(Serialize)]
struct Body {
id: u64,
version_id: u64,
text: String,
timestamp: String,
sender: String,
metadata: Metadata,
}
#[derive(Serialize)]
struct Payload {
body: Body,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let payload = Payload {
body: Body {
id: 152948599,
version_id: 1856687097,
text: "bWFya2V0IGVudHJ5IGZvciBFdXJvcGVhbiBkYWlyeSBwcm9kdWNlciBpbiBVQUU=".into(),
timestamp: "1702307960".into(),
sender: "user".into(),
metadata: Metadata {
conversationTopic: "TmV3IENoYXQ=".into(),
tool: vec!["Y2hhdGJvdA==".into(), "aW5zdHJ1Y3Rpb24=".into(), "dG9uZQ==".into(), "bGVuZ3Ro".into()],
reference: vec!["Z3B0My41LXR1cmJv".into(), "cHJvZmVzc2lvbmFs".into(), "cHJvZmVzc2lvbmFs".into(), "c2hvcnQ=".into()],
token_cost: 2138,
rating: 1,
},
},
};
let res = client
.post("https://LAMBDA_ENDPOINT.us-east-2.<CLOUDHOST>.com/v1/<?HOOK>")
.header("Authorization", "<token>")
.json(&payload)
.send()
.await?;
println!("{:?}", res.text().await?);
Ok(())
}
@GoLang (gopher/net/http idioms)
package main
import (
"encoding/base64"
"bytes"
"encoding/json"
"fmt"
"net/http"
)
// Encode
func encodeBase64(input string) string {
return base64.StdEncoding.EncodeToString([]byte(input))
}
// Decode
func decodeBase64(input string) (string, error) {
bytes, err := base64.StdEncoding.DecodeString(input)
return string(bytes), err
}
func main() {
url := "https://LAMBDA_ENDPOINT.us-east-2.<CLOUDHOST>.com/v1/<?HOOK>"
payload := map[string]interface{}{
"body": map[string]interface{}{
"id": 152948599,
"version_id": 1856687097,
"text": "bWFya2V0IGVudHJ5IGZvciBFdXJvcGVhbiBkYWlyeSBwcm9kdWNlciBpbiBVQUU=",
"timestamp": "1702307960",
"sender": "user",
"metadata": map[string]interface{}{
"conversationTopic": "TmV3IENoYXQ=",
"tool": []string{"Y2hhdGJvdA==", "aW5zdHJ1Y3Rpb24=", "dG9uZQ==", "bGVuZ3Ro"},
"reference": []string{"Z3B0My41LXR1cmJv", "cHJvZmVzc2lvbmFs", "cHJvZmVzc2lvbmFs", "c2hvcnQ="},
"token_cost": 2138,
"rating": 1,
},
},
}
jsonData, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "<token>")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
fmt.Println(resp.Status)
}
CUDA C (host-side HTTP via libcurl, on CUDA, only HOST-flagged coprophiliacs can raw-thrash that ass)
#include <curl/curl.h>
int main() {
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://LAMBDA_ENDPOINT.us-east-2.<CLOUDHOST>.com/v1/<?⚡HOOK>");⚡
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "Authorization: <token>");
const char *json =
"{\"body\":{\"id\":152948599,\"version_id\":1856687097,"
"\"text\":\"bWFya2V0...\",\"timestamp\":\"1702307960\","
"\"sender\":\"user\"}}";
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
Then using SSL
#include <openssl/evp.h>
#include <string.h>
// Encode
char* encode_base64(const unsigned char* input, int length) {
int out_len = 4 * ((length + 2) / 3);
char* output = (char*)malloc(out_len + 1);
EVP_EncodeBlock((unsigned char*)output, input, length);
return output;
}
// Decode
unsigned char* decode_base64(const char* input, int* out_len) {
int len = strlen(input);
unsigned char* output = (unsigned char*)malloc(len);
*out_len = EVP_DecodeBlock(output, (const unsigned char*)input, len);
return output;
}
Ruby on Rails (Net::HTTP built-in idiom)
require "net/http"
require "json"
require "base64"
# Encode
def encode_base64(str)
Base64.strict_encode64(str)
end
# Decode
def decode_base64(b64)
Base64.decode64(b64)
end
uri = URI("https://LAMBDA_ENDPOINT.us-east-2.<CLOUDHOST>.com/v1/<?HOOK>")
payload = {
body: {
id: 152948599,
version_id: 1856687097,
text: "bWFya2V0IGVudHJ5IGZvciBFdXJvcGVhbiBkYWlyeSBwcm9kdWNlciBpbiBVQUU=",
timestamp: "1702307960",
sender: "user",
metadata: {
conversationTopic: "TmV3IENoYXQ=",
tool: ["Y2hhdGJvdA==","aW5zdHJ1Y3Rpb24=","dG9uZQ==","bGVuZ3Ro"],
reference: ["Z3B0My41LXR1cmJv","cHJvZmVzc2lvbmFs","cHJvZmVzc2lvbmFs","c2hvcnQ="],
token_cost: 2138,
rating: 1
}
}
}
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request["Content-Type"] = "application/json"
request["Authorization"] = "<token>"
request.body = payload.to_json
response = http.request(request)
puts response.body