AI Text Generation API Documentation

 

This document outlines the usage and specifications of the AI Text Generation API. Powered by advanced artificial intelligence models, this API can generate high-quality text based on user-provided prompts. It is ideal for use cases such as intelligent writing assistants, content creation tools, and chatbots.

  • API Name: AI Text Generation API

  • Version: 1.0

  • HTTP Method: POST

  • Endpointhttps://api.example.com/ai/text/generate

ParameterTypeRequiredDescription
promptstringYesInput prompt to guide the text generation
max_tokensintNoMaximum length of generated text, default is 100
temperaturefloatNoControls randomness of output; range: 0–1, default is 0.7
ParameterTypeDescription
codeintResponse status code (200 = success)
messagestringResponse message, empty on success
dataobjectContains the generated text
- textstringThe generated text content
{
    "prompt": "Write an introduction about artificial intelligence.",
    "max_tokens": 200,
    "temperature": 0.8
}
{
    "code": 200,
    "message": "",
    "data": {
        "text": "Artificial intelligence is a technology that simulates human intelligence, enabling computers to perform tasks such as learning, reasoning, and self-correction."
    }
}
{
    "code": 400,
    "message": "Invalid request parameters",
    "data": null
}
Error CodeMessageCauseSolution
400Bad RequestInvalid request parametersVerify and correct parameters before resubmitting
401UnauthorizedMissing or invalid credentialsEnsure valid API key is used in the Authorization header
500Internal Server ErrorServer-side issueContact support or retry after some time
  • Security: Data transmission is secured via HTTPS.

  • Authentication: API key required. Add the Authorization header in the format Bearer your_api_key.

import requests

url = "https://api.example.com/ai/text/generate"
headers = {
    "Authorization": "Bearer your_api_key",
    "Content-Type": "application/json"
}
data = {
    "prompt": "Write an introduction about artificial intelligence.",
    "max_tokens": 200,
    "temperature": 0.8
}

response = requests.post(url, headers=headers, json=data)

if response.status_code == 200:
    print(response.json()["data"]["text"])
else:
    print("Error:", response.status_code, response.json()["message"])
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class ApiExample {
    public static void main(String[] args) throws IOException, InterruptedException {
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.example.com/ai/text/generate"))
            .header("Authorization", "Bearer your_api_key")
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString("{\"prompt\": \"Write an introduction about artificial intelligence.\", \"max_tokens\": 200, \"temperature\": 0.8}"))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

        if (response.statusCode() == 200) {
            System.out.println(response.body());
        } else {
            System.out.println("Error: " + response.statusCode() + ", " + response.body());
        }
    }
}
  • Performance Metrics: Average response time per request is approximately 1 second.

  • Release Notes: Version 1.0 released on June 19, 2025.

  • ReferenceOpenAI Official Documentation

Note: This is a sample API reference. Please adjust the details to match the actual specifications of your API when implementing it in a production environment.

评论

此博客中的热门博文

Why Is an AI Meeting Notes App Worth $250 Million? How Granola Stands Out in a Crowded Market

Beyond Trial-and-Error: A New Framework for Efficient LLM Selection, Backed by ICML 2025