Skip to content

Instantly share code, notes, and snippets.

@harishkotra
Created October 15, 2025 15:44
Show Gist options
  • Save harishkotra/82e76228d5e7fc6e770afab88a89611a to your computer and use it in GitHub Desktop.
Save harishkotra/82e76228d5e7fc6e770afab88a89611a to your computer and use it in GitHub Desktop.
openai compatible api with gaia nodes.
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { generateText } from "ai";
import "dotenv/config";
function gaiaFetch(input, init) {
const headers = new Headers(init?.headers ?? {});
// Set headers only if they are not already present
if (!headers.has("accept")) {
headers.set("accept", "application/json");
}
if (!headers.has("content-type")) {
headers.set("content-type", "application/json");
}
// It's good practice to identify your application with a custom user-agent
if (!headers.has("user-agent")) {
headers.set("user-agent", "MyGaiaApp/1.0");
}
return fetch(input, {
...init,
headers,
});
}
// Configure the Gaia provider using createOpenAI
export const gaia = createOpenAICompatible({
baseURL: 'https://0x34d996c47b2c00e39b37dfd70aac5beaaf25d2c8.gaia.domains/v1',
apiKey: 'gaia',
});
// Main function to run the application
async function main() {
try {
const { text } = await generateText({
model: gaia('Qwen3-4B-Q5_K_M'),
prompt: 'Write a short poem about a cat.',
});
console.log(text);
} catch (error) {
console.error("Error:", error);
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment