DEV Community

Cover image for I Built a Free AI API With No Login, No API Key, and 5 AI Models
Daivik Dagar
Daivik Dagar

Posted on

I Built a Free AI API With No Login, No API Key, and 5 AI Models

I have made a totally free for all AI API (requires no key or account) which requires no keys and no login. I made this possible by Cloudflare workers, my API offers free 60,000 requests/day and 20 requests/min. API has smart fallback system and 5 different models.

API Request URL: https://dg-ai.scriptsnsenses.workers.dev/

API Playground: https://dg-ai.scriptsnsenses.workers.dev/

Wiring example:

// Example: How to connect your app to the Free AI API
async function askAI(userPrompt) {
  const API_URL = "https://dg-ai.scriptsnsenses.workers.dev/";

  try {
    const response = await fetch(API_URL, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        messages: [
          { 
            role: "system", 
            content: "You are a helpful assistant." 
          },
          { 
            role: "user", 
            content: userPrompt 
          }
        ]
      })
    });

    const data = await response.json();

    // Extract the text response from the model
    const reply = data.response.choices[0].message.content;
    console.log("AI Reply:", reply);
    return reply;

  } catch (error) {
    console.error("Error calling the AI API:", error);
  }
}

// Usage:
askAI("Give me a 3-word motto for a programmer.");
Enter fullscreen mode Exit fullscreen mode

You can also use other models. We offer 5 models:

  • ChatGPT (gpt-oss-120b)
  • DeepSeek (r1-distill-32b)
  • Qwen 12B (qwen-2.5-7b)
  • Gemma (3-12b-it)
  • Qwen Coder (2.5-32b)

ChatGPT wiring example (gpt-oss-120b):

// Example: How to connect your app specifically to the ChatGPT model
async function askChatGPT(userPrompt) {
  // Your specific ChatGPT model endpoint path
  const API_URL = "https://dg-ai.scriptsnsenses.workers.dev/v1/chat/gpt-oss-120b";

  try {
    const response = await fetch(API_URL, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        messages: [
          { 
            role: "system", 
            content: "You are a helpful assistant." 
          },
          { 
            role: "user", 
            content: userPrompt 
          }
        ]
      })
    });

    const data = await response.json();

    // Extract the text response from the model
    const reply = data.response.choices[0].message.content;
    console.log("ChatGPT Reply:", reply);
    return reply;

  } catch (error) {
    console.error("Error calling ChatGPT:", error);
  }
}

// Usage:
askChatGPT("Write a funny 1-line error message for a broken server connection.");
Enter fullscreen mode Exit fullscreen mode

DeepSeek wiring example (r1-distill-32b):

// Example: How to connect your app specifically to the DeepSeek model
async function askDeepSeek(userPrompt) {
  // Your specific DeepSeek model endpoint path
  const API_URL = "https://dg-ai.scriptsnsenses.workers.dev/v1/chat/r1-distill-32b";

  try {
    const response = await fetch(API_URL, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        messages: [
          { 
            role: "system", 
            content: "You are a helpful assistant." 
          },
          { 
            role: "user", 
            content: userPrompt 
          }
        ]
      })
    });

    const data = await response.json();

    // Extract the text response from the model
    const reply = data.response.choices[0].message.content;
    console.log("DeepSeek Reply:", reply);
    return reply;

  } catch (error) {
    console.error("Error calling DeepSeek:", error);
  }
}

// Usage:
askDeepSeek("Explain the concept of serverless computing in one simple sentence.");
Enter fullscreen mode Exit fullscreen mode

Qwen 12B (qwen-2.5-7b):

// Example: How to connect your app specifically to the Qwen 12B model
async function askQwen(userPrompt) {
  // Your specific Qwen 12B model endpoint path
  const API_URL = "https://dg-ai.scriptsnsenses.workers.dev/v1/chat/qwen-2.5-7b";

  try {
    const response = await fetch(API_URL, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        messages: [
          { 
            role: "system", 
            content: "You are a helpful assistant." 
          },
          { 
            role: "user", 
            content: userPrompt 
          }
        ]
      })
    });

    const data = await response.json();

    // Extract the text response from the model
    const reply = data.response.choices[0].message.content;
    console.log("Qwen Reply:", reply);
    return reply;

  } catch (error) {
    console.error("Error calling Qwen 12B:", error);
  }
}

// Usage:
askQwen("Give me a quick recipe idea using just eggs, tomatoes, and bread.");
Enter fullscreen mode Exit fullscreen mode

Qwen Coder (2.5-32b):

// Example: How to connect your app specifically to the Qwen Coder model
async function askQwenCoder(userPrompt) {
  // Your specific Qwen Coder model endpoint path
  const API_URL = "https://dg-ai.scriptsnsenses.workers.dev/v1/chat/2.5-32b";

  try {
    const response = await fetch(API_URL, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        messages: [
          { 
            role: "system", 
            content: "You are an expert software engineer assistant." 
          },
          { 
            role: "user", 
            content: userPrompt 
          }
        ]
      })
    });

    const data = await response.json();

    // Extract the text response from the model
    const reply = data.response.choices[0].message.content;
    console.log("Qwen Coder Reply:", reply);
    return reply;

  } catch (error) {
    console.error("Error calling Qwen Coder:", error);
  }
}

// Usage:
askQwenCoder("Write a quick JavaScript function to reverse a string.");
Enter fullscreen mode Exit fullscreen mode

Thanks for Reading

Comment down which AI model or new feature you would like to see next !!

Top comments (1)

Collapse
 
daivik_dagar_f88cb5415125 profile image
Daivik Dagar

There is a error currently at 6:23 PM (Global Standard Time) will be fixed shortly