Documentation
API

API

fetch-request
await fetch("https://api.oneword.domains/gpt/generate", {
    "method": "POST",
    "headers": {
        "Authorization": "Bearer <TOKEN>",
        "Content-Type": "application/json"
    },
    "body": JSON.stringify({
        // Request parameters
    })
})

Request parameters

These are the request parameters that should be included in the body of the request. While none of the request parameters are required, they are useful for customizing the generated output.

If left undefined, the default values for each parameter will be used.

ParameterTypeDescriptionDefault
typestringThe type of name to generate. Refer to the Name Types section for all the possible values."random"
contextstringAdded context about the nature of the business or product to generate the name for. E.g. "An AI-powered personal finance assistant that optimizes your spending, saving, and investing habits."undefined
minLengthnumberThe minimum length of the generated name.7
maxLengthnumberThe maximum length of the generated name.12
wordstringA word to be included in the generated name.undefined
positionstringThe position of the word to be included in the generated name (only used when word is defined). Possible values: "prefix", "suffix", "anywhere"."prefix"
tldstringThe top-level domain to be appended to the generated name."com"
domainsstring[]A list of previously-generated domains (to avoid duplicates).[]

Name Types

The type parameter can be set to any of the following values:

ValueDescriptionExamples
"portmanteau"Names that are a creative blend of two words"Pinterest", "Instagram", "FedEx"
"combination"Names that are two-word combinations"Facebook", "YouTube", "OpenDoor"
"brandable"Names that don't have a specific meaning but are memorable"Google", "Rolex", "Ikea", "Nike", "Quora"
"nonenglish"Names that are non-English words"Toyota", "Audi", "Nissan"
"alternate"Names that are misspellings of existing words"Lyft", "Fiverr", "Dribbble"
"random"Let the AI do its thing ✨"TikTok", "Airbnb", "Netflix"

Response

The response from the API is a ReadableStream (opens in a new tab) of stringified JSON objects.

Response
{ "domain": "openflicker.com", "available": true } { "domain": "openlyric.com", "available": false }

You have the option to stream the response directly to the client as it is generated, or you can wait for the entire response to be received before sending it to the client. For a better user experience, we highly recommend the former approach.

Method 1: Streaming the response (Recommended)

You can stream the response directly to the client as it is generated by using the getReader() method on the response object. Here's an example:

App.js
const [domains, setDomains] = useState([]);
const [generating, setGenerating] = useState(false);
 
const generateDomain = async () => {
  setDomains([]);
  setGenerating(true);
  const response = await fetch("https://api.oneword.domains/gpt/generate", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      type: "portmanteau",
      word: "open",
      position: "prefix",
    }),
  });
 
  // This data is a ReadableStream
  const data = response.body;
  if (!data) {
    return;
  }
 
  const reader = data.getReader();
  const decoder = new TextDecoder();
  let done = false;
  let tempState = "";
 
  while (!done) {
    const { value, done: doneReading } = await reader.read();
    done = doneReading;
    let chunkValue = decoder.decode(value);
 
    // Here, we are defining a temporary state because the response stream
    // can get fragmented due to the behavior/distance between the client
    // and the server. So, we need to keep track of the previous chunk
    // and append it to the current chunk to make sure we have a complete
    // JSON string.
    if (tempState) {
      chunkValue = tempState + chunkValue;
      tempState = "";
    }
 
    // Here, we match the complete JSON string and extract it from the chunk
    // and save the remaining string in the tempState variable.
    const match = chunkValue.match(/\{(.*?)\}/);
    if (match) {
      tempState = chunkValue.replace(match[0], "");
      chunkValue = match[0];
    }
 
    try {
      const { domain, available } = JSON.parse(chunkValue);
      setDomains((prev) => [...prev, { domain, available }]);
    } catch (e) {
      // if the JSON.parse method fails, it means that the chunkValue
      // is not a complete JSON string and the stream is fragmented.
      // So, we save the chunkValue in the tempState variable and
      // append it to the next chunk.
      tempState = chunkValue;
    }
  }
  setGenerating(false);
};

You can see this example in action in the demo below:


import { useRef, useState } from "react";

export default function Generator() {
  const bottomRef = useRef(null);
  const [domains, setDomains] = useState([]);
  const [generating, setGenerating] = useState(false);

  const generateDomain = async () => {
    setDomains([]);
    setGenerating(true);
    const response = await fetch("https://api.oneword.domains/gpt/generate", {
      method: "POST",
      headers: {
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
        type: "portmanteau",
        word: "open",
        position: "prefix"
      })
    });

    // Handle rate limits
    if (!response.ok) {
      alert("You've reached your usage limit. Enter an API key to continue.");
      setGenerating(false);
      return;
    }

    // This data is a ReadableStream
    const data = response.body;
    if (!data) {
      return;
    }

    const reader = data.getReader();
    const decoder = new TextDecoder();
    let done = false;
    let tempState = "";

    while (!done) {
      const { value, done: doneReading } = await reader.read();
      done = doneReading;
      let chunkValue = decoder.decode(value);

      if (tempState) {
        chunkValue = tempState + chunkValue;
        tempState = "";
      }

      // match json string and extract it from the chunk
      const match = chunkValue.match(/{(.*?)}/);
      if (match) {
        tempState = chunkValue.replace(match[0], "");
        chunkValue = match[0];
      }

      try {
        const { domain, available } = JSON.parse(chunkValue);
        setDomains((prev) => [...prev, { domain, available }]);
        scrollTo({
          top:
            bottomRef.current.getBoundingClientRect().top +
            window.pageYOffset -
            (window.innerHeight - 50),
          behavior: "smooth"
        });
      } catch (e) {
        tempState = chunkValue;
      }
    }
    setGenerating(false);
  };

  return (
    <div className="p-5">
      <h1 className="text-2xl font-bold">DomainsGPT Demo</h1>
      <button
        onClick={generateDomain}
        disabled={generating}
        className={
          "my-2 rounded-md border border-black bg-black px-3 py-1 font-medium text-white transition-all hover:bg-white hover:text-black" +
          (generating
            ? "cursor-not-allowed border-gray-200 bg-gray-100 text-gray-300"
            : "")
        }
      >
        {generating ? "Generating..." : "Generate Domains"}
      </button>
      <ul className="my-2 grid grid-cols-2 gap-3">
        {domains.map(({ domain, available }, index) => {
          return (
            <li
              key={index}
              className="flex items-center justify-between rounded-md border border-gray-200 p-2 shadow-md"
            >
              <p className="font-medium">{domain}</p>
              {available ? (
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  width="24"
                  height="24"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="#22C55E"
                  strokeWidth="2"
                  strokeLinecap="round"
                  strokeLinejoin="round"
                >
                  <polyline points="20 6 9 17 4 12"></polyline>
                </svg>
              ) : (
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  width="24"
                  height="24"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="#DC2626"
                  strokeWidth="2"
                  strokeLinecap="round"
                  strokeLinejoin="round"
                >
                  <line x1="18" x2="6" y1="6" y2="18"></line>
                  <line x1="6" x2="18" y1="6" y2="18"></line>
                </svg>
              )}
            </li>
          );
        })}
      </ul>
      <div ref={bottomRef} />
    </div>
  );
}

Method 2: Awaiting the response

If you really want to wait for the entire response to be received before sending it to the client, you can do so with the following code:

App.js
const [domains, setDomains] = useState([]);
const [generating, setGenerating] = useState(false);
 
const generateDomain = async () => {
  setDomains([]);
  setGenerating(true);
  const response = await fetch("https://api.oneword.domains/gpt/generate", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      type: "portmanteau",
      word: "open",
      position: "prefix",
    }),
  }).then((res) => res.text());
 
  const domainsArray = response
    .split("}")
    .filter((str) => str.trim() !== "")
    .map((str) => str.trim() + "}")
    .map((objectString) => JSON.parse(objectString));
 
  setDomains(domainsArray);
  setGenerating(false);
};

You can see this example in action in the demo below:


import { useState } from "react";

export default function Generator() {
  const [domains, setDomains] = useState([]);
  const [generating, setGenerating] = useState(false);

  const generateDomain = async () => {
    setDomains([]);
    setGenerating(true);
    const response = await fetch("https://api.oneword.domains/gpt/generate", {
      method: "POST",
      headers: {
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
        type: "portmanteau",
        word: "open",
        position: "prefix"
      })
    })

    // Handle rate limits
    if (!response.ok) {
      alert("You've reached your usage limit. Enter an API key to continue.");
      setGenerating(false);
      return;
    }

    const domainsArray = (await response.text())
      .split("}")
      .filter((str) => str.trim() !== "")
      .map((str) => str.trim() + "}")
      .map((objectString) => JSON.parse(objectString));

    setDomains(domainsArray);
    setGenerating(false);
  };

  return (
    <div className="p-5">
      <h1 className="text-2xl font-bold">DomainsGPT Demo</h1>
      <button
        onClick={generateDomain}
        disabled={generating}
        className={
          "my-2 rounded-md border border-black bg-black px-3 py-1 font-medium text-white transition-all hover:bg-white hover:text-black" +
          (generating
            ? "cursor-not-allowed border-gray-200 bg-gray-100 text-gray-300"
            : "")
        }
      >
        {generating ? "Generating..." : "Generate Domains"}
      </button>
      <ul className="my-2 grid grid-cols-2 gap-3">
        {domains.map(({ domain, available }, index) => {
          return (
            <li
              key={index}
              className="flex items-center justify-between rounded-md border border-gray-200 p-2 shadow-md"
            >
              <p className="font-medium">{domain}</p>
              {available ? (
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  width="24"
                  height="24"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="#22C55E"
                  strokeWidth="2"
                  strokeLinecap="round"
                  strokeLinejoin="round"
                >
                  <polyline points="20 6 9 17 4 12"></polyline>
                </svg>
              ) : (
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  width="24"
                  height="24"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="#DC2626"
                  strokeWidth="2"
                  strokeLinecap="round"
                  strokeLinejoin="round"
                >
                  <line x1="18" x2="6" y1="6" y2="18"></line>
                  <line x1="6" x2="18" y1="6" y2="18"></line>
                </svg>
              )}
            </li>
          );
        })}
      </ul>
    </div>
  );
}