Dvi-Coder.js — Exposure API

Version 3.0.0 · Serverless · Free Forever · No Backend

Created by Clobax-Creator (Avyaan Mishra) · GPL v3

Quick Start

Include the SDK in your HTML:

Create an instance:

const dc = new DviCoder({
  apiKey: 'your-api-key',
  provider: 'openrouter',  // sarvam, openai, groq, openrouter, or custom
  // baseUrl: 'https://custom-api.com/v1',  // optional, for custom
  // model: 'gpt-4o',        // optional, auto-detected if omitted
  // temperature: 0.7,       // optional (default 0.7)
  // maxTokens: 4096,        // optional (default 4096)
});

Supported Providers

ProviderKey FormatBase URL
sarvamsk_...https://api.sarvam.ai/v1
openaisk-...https://api.openai.com/v1
groqgsk_...https://api.groq.com/openai/v1
openroutersk-or-v1-...https://openrouter.ai/api/v1
customanyyour-url

API Methods

dc.chat(message, history?)

Send a chat message to the AI. Returns the response text.

const reply = await dc.chat('Write a Python function to sort a list');
console.log(reply);

// With custom history (doesn't use internal history)
const reply2 = await dc.chat('Explain it simpler', [
  { role: 'user', content: 'Write a Python function to sort a list' },
  { role: 'assistant', content: 'def sort_list(l): return sorted(l)' },
]);

message (string) — User's message

history (array, optional) — Override chat history

Returns Promise — AI response

dc.chatStream(message, onToken, history?)

Stream a chat response token-by-token. Calls onToken for each chunk.

await dc.chatStream('Write a story', (chunk, fullText) => {
  document.getElementById('output').textContent = fullText;
});

message (string) — User's message

onToken (function) — Callback(chunk, fullText)

history (array, optional) — Override chat history

Returns Promise — Full response text

dc.models()

List available models from the AI provider.

const models = await dc.models();
// ['sarvam-m', 'sarvam-2b', 'gpt-4o', ...]
dc.setModel('gpt-4o');

Returns Promise> — Model IDs

dc.githubList(owner, repo, token, branch?)

List all files in a GitHub repo (recursive).

const files = await dc.githubList('pandeykhushbu29-eng', 'Dvidvar', 'ghp_xxx');
// [{ path: 'README.md', size: 5000 }, { path: 'ISA.md', size: 12000 }, ...]

Returns Promise>

dc.githubRead(owner, repo, path, token)

Read a file from a GitHub repo.

const file = await dc.githubRead('user', 'repo', 'README.md', 'ghp_xxx');
console.log(file.content); // file text content

Returns Promise<{path, content, size}>

dc.githubCommit(owner, repo, path, content, token, message?, branch?)

Create or update a file in a GitHub repo.

await dc.githubCommit('user', 'repo', 'test.py', 'print("hello")', 'ghp_xxx', 'Add test.py');

Returns Promise<{success, commitUrl}>

dc.hfUpload(repo, path, content, token)

Upload a file to a Hugging Face repo (Space, model, or dataset).

await dc.hfUpload('Clobax-Creator/Dvidata', 'data.json', '{"key":"value"}', 'hf_xxx');

Returns Promise<{success, url}>

dc.hfList(repo, token)

List files in a Hugging Face repo.

const files = await dc.hfList('Clobax-Creator/Dvidata', 'hf_xxx');
// [{ path: 'README.md', size: 2000 }, ...]

Returns Promise>

Utility Methods

dc.clearHistory()

Clear the internal chat history.

dc.setModel(model)

Change the AI model.

dc.setModel('gpt-4o');
dc.setProvider(provider, baseUrl?)

Change the AI provider and/or base URL.

dc.setProvider('groq');
dc.setProvider('custom', 'https://my-api.com/v1');

How It Works

Everything runs in the browser. No backend, no server, no cost.

User's browser
  ├── Downloads dvi-coder.js (one time, from HF static hosting)
  ├── Calls AI API directly (Sarvam/OpenAI/Groq/OpenRouter)
  ├── Calls GitHub API directly (CORS supported)
  └── Calls HuggingFace API directly (CORS supported)

You host the JS file on HF Static Spaces (free). Developers include it. Their users' browsers do all the work. You pay nothing. They pay nothing. The only cost is each user's own API key.

Full Example App




  


  
  
  

Dvi-Coder.js v3.0.0 · Clobax-Creator (Avyaan Mishra) · GPL v3