Comprehensive reference for all exported functions, types, and interfaces in the Gambiarra SDK.
createGambiarra()
Creates a Gambiarra provider for use with Vercel AI SDK.
function createGambiarra(options: GambiarraOptions): GambiarraProvider
Parameters
Configuration options for the provider
The 6-character room code to connect to
hubUrl
string
default:"http://localhost:3000"
Base URL of the Gambiarra hub
Returns
Provider interface with routing methods and utilities
participant
(id: string) => LanguageModel
Route to a specific participant by ID
model
(name: string) => LanguageModel
Route to the first participant running the specified model
Route to any random online participant
listParticipants
() => Promise<ParticipantInfo[]>
List all participants in the room
listModels
() => Promise<GambiarraModel[]>
List available models in OpenAI-compatible format
Base URL for direct OpenAI-compatible API access
Example
import { createGambiarra } from "gambiarra-sdk";
import { generateText } from "ai";
const gambiarra = createGambiarra({ roomCode: "ABC123" });
const result = await generateText({
model: gambiarra.any(),
prompt: "Hello!",
});
Provider Methods
participant()
Route requests to a specific participant by ID.
participant(id: string): LanguageModel
The unique identifier of the participant
Example
const result = await generateText({
model: gambiarra.participant("participant-123"),
prompt: "Route to specific machine",
});
model()
Route requests to the first online participant running the specified model.
model(name: string): LanguageModel
The model name to match (e.g., “llama3”, “gpt-4”)
Example
const result = await generateText({
model: gambiarra.model("llama3"),
prompt: "Use Llama 3 model",
});
The model name is prefixed with model: internally, so gambiarra.model("llama3") becomes model:llama3 in the routing layer.
any()
Route requests to any random online participant.
Example
const result = await generateText({
model: gambiarra.any(),
prompt: "Use any available participant",
});
Internally uses the model ID * which the hub interprets as “any random online participant”.
listParticipants()
Retrieve all participants in the room.
listParticipants(): Promise<ParticipantInfo[]>
Returns
Array of participant information objects
Unique participant identifier
Human-readable participant name
Model name (e.g., “llama3”, “gpt-4”)
OpenAI-compatible endpoint URL
Timestamp of last health check (Unix milliseconds)
Hardware specifications
GPU model (e.g., “RTX 4090”)
Default generation configuration
Sampling temperature (0.0 to 2.0)
Maximum tokens to generate
Nucleus sampling threshold
Frequency penalty (-2.0 to 2.0)
Presence penalty (-2.0 to 2.0)
Example
const participants = await gambiarra.listParticipants();
participants.forEach((p) => {
console.log(`${p.nickname}: ${p.status}`);
if (p.specs) {
console.log(` GPU: ${p.specs.gpu}, VRAM: ${p.specs.vram}GB`);
}
});
listModels()
Retrieve available models in OpenAI-compatible format.
listModels(): Promise<GambiarraModel[]>
Returns
Array of model information objects
Model identifier (participant ID in Gambiarra)
Actual model name (e.g., “llama3”)
OpenAI-compatible endpoint URL
Example
const models = await gambiarra.listModels();
models.forEach((m) => {
console.log(`${m.id}: ${m.model} at ${m.endpoint}`);
});
HTTP Client
createClient()
Create an HTTP client for managing rooms and participants.
function createClient(options?: ClientOptions): GambiarraClient
Parameters
Client configuration options
hubUrl
string
default:"http://localhost:3000"
Base URL of the Gambiarra hub
Returns
Client interface with room and participant management methods
Example
import { createClient } from "gambiarra-sdk";
const client = createClient({ hubUrl: "http://hub.local:3000" });
Client Methods
create()
Create a new room.
create(name: string, password?: string): Promise<CreateRoomResponse>
Optional password for room protection
Returns
Created room information
Creation timestamp (Unix milliseconds)
Number of participants in the room
ID of the host participant
Example
const { room, hostId } = await client.create("My Room", "secret123");
console.log(`Created room: ${room.code}`);
list()
List all rooms on the hub.
list(): Promise<RoomInfo[]>
Returns
Array of room information objects
Example
const rooms = await client.list();
rooms.forEach((r) => {
console.log(`${r.name} (${r.code}): ${r.participantCount} participants`);
});
join()
Join a room as a participant.
join(
code: string,
participant: CreateParticipantOptions
): Promise<JoinRoomResponse>
participant
CreateParticipantOptions
required
Participant configurationShow CreateParticipantOptions
Unique participant identifier
Human-readable participant name
Model name (e.g., “llama3”)
OpenAI-compatible endpoint URL
Room password (required if room is protected)
Default generation configuration
Returns
Created participant information
Example
const { participant, roomId } = await client.join("ABC123", {
id: "my-bot",
nickname: "My Ollama",
model: "llama3",
endpoint: "http://localhost:11434",
specs: {
gpu: "RTX 4090",
vram: 24,
},
});
leave()
Leave a room.
leave(code: string, participantId: string): Promise<{ success: boolean }>
Example
await client.leave("ABC123", "my-bot");
console.log("Left the room");
getParticipants()
Get all participants in a room.
getParticipants(code: string): Promise<ParticipantInfo[]>
Example
const participants = await client.getParticipants("ABC123");
console.log(`${participants.length} participants in room`);
healthCheck()
Send a health check for a participant.
healthCheck(
code: string,
participantId: string
): Promise<{ success: boolean }>
Participant ID sending the health check
Health checks should be sent every 10 seconds. Participants are marked offline after 30 seconds of inactivity.
Example
setInterval(async () => {
await client.healthCheck("ABC123", "my-bot");
}, 10_000);
Error Classes
ClientError
Error thrown when HTTP client requests fail.
class ClientError extends Error {
readonly status: number;
readonly response?: unknown;
}
Original response data from the server
Example
import { ClientError } from "gambiarra-sdk";
try {
await client.join("INVALID", participant);
} catch (error) {
if (error instanceof ClientError) {
console.error(`HTTP ${error.status}: ${error.message}`);
console.error("Response:", error.response);
}
}
Type Exports
All core types from @gambiarra/core are re-exported:
import type {
// Room types
RoomInfo,
// Participant types
ParticipantInfo,
ParticipantStatus,
// Configuration types
GenerationConfig,
MachineSpecs,
HubConfig,
NetworkConfig,
OllamaConfig,
// Chat types
ChatCompletion,
ChatCompletionChunk,
ChatCompletionMessage,
ChatCompletionMessageParam,
ChatCompletionCreateParams,
// Model types
Model,
ModelDeleted,
LlmMetrics,
} from "gambiarra-sdk";
Schema Exports
Zod schemas for runtime validation (exported with Schema suffix):
import {
ParticipantInfoSchema,
RoomInfoSchema,
GenerationConfigSchema,
MachineSpecsSchema,
HubConfigSchema,
NetworkConfigSchema,
OllamaConfigSchema,
ParticipantStatusSchema,
LlmMetricsSchema,
} from "gambiarra-sdk";
// Validate at runtime
const result = ParticipantInfoSchema.parse(data);
Constants
Exported timing constants:
import {
HEALTH_CHECK_INTERVAL,
PARTICIPANT_TIMEOUT,
} from "gambiarra-sdk";
console.log(HEALTH_CHECK_INTERVAL); // 10000 (10 seconds)
console.log(PARTICIPANT_TIMEOUT); // 30000 (30 seconds)
Namespaces
Re-exported namespaces from @gambiarra/core:
rooms
import { rooms } from "gambiarra-sdk";
// Room management
const room = rooms.create("Room Name", "host-id");
const room = rooms.get(id);
const room = rooms.getByCode(code);
const allRooms = rooms.list();
rooms.remove(id);
// Participant management
rooms.addParticipant(roomId, participant);
rooms.removeParticipant(roomId, participantId);
const participants = rooms.getParticipants(roomId);
participants
import { participants } from "gambiarra-sdk";
const participant = participants.create({
nickname: "Bot",
model: "llama3",
endpoint: "http://localhost:11434",
specs: { gpu: "RTX 4090", vram: 24 },
});
hub
import { hub } from "gambiarra-sdk";
const myHub = hub.create({
port: 3000,
hostname: "0.0.0.0",
mdns: true,
});
console.log(myHub.url); // http://0.0.0.0:3000
myHub.close();
Next Steps
Usage Guide
Learn practical usage patterns and examples
Quickstart
Build your first Gambiarra application