4EVERLAND Documents
HomeTwitterDiscordBlogs
  • Welcome to 4EVERLAND
  • Get started
    • Our Features
    • Quick Start Guide
      • Registration
      • Login options
        • MetaMask
        • OKX Wallet
        • Binance Web3 Wallet
        • Bitget Wallet
        • Phantom
        • Petra
        • Lilico
      • Usage Introduction
      • Dashboard stats
      • Account
        • Linking Your EVM Wallet to 4EVERLAND Account
        • Balance Alert
    • Billing and Pricing
      • What is LAND?
      • How to Obtain LAND?
      • Pricing Model
      • Q&As
    • Tokenomics
  • HOSITNG
    • What is Hosting?
      • IPFS Hosting
      • Arweave Hosting
        • Auto-Generation of Manifest
      • Internet Computer Hosting
      • Greenfield Hosting
    • Guides
      • Creating a Deployment
        • With Git
        • With IPFS Hash
        • With a Template
      • Site Deployment
      • Domain Management
        • DNS Setup Guide
        • ENS Setup Guide
        • SNS Setup Guide
          • The gateway: 4sol.xyz
        • SPACE ID Setup Guide
      • Project Setting
        • Git
      • Troubleshooting
      • Common Frameworks
    • Hosting Templates Centre
      • Templates Configuration File
    • Quick Addition
      • Implement Github 4EVER Pin
      • Github Deployment Button
    • Hosting API
      • Create Project API
      • Deploy Project API
      • Get Task Info API
      • IPNS Deployment Update API
    • Hosting CLI
  • Storage
    • Bucket
      • IPFS Bucket
        • Get Root CID - Snapshots
      • Arweave Bucket
        • Path Manifests
          • Instructions for Building Manifest
          • Auto-Generation of Manifest
        • Arweave Tags
        • Unleash Arweave
      • Guides
      • Bucket API - S3 Compatible
        • Coding Examples
          • AWS SDK - Go (Golang)
          • AWS SDK - Java
          • AWS SDK - JavaScript
          • AWS SDK - .NET
          • AWS SDK - PHP
          • AWS SDK - Python
          • AWS SDK - Ruby
        • S3 Tags Instructions
      • 4EVER Security Token Service API
      • Bucket Tools
      • Bucket Gateway Optimizer
    • 4EVER Pin
      • Guides
      • Pinning Services API
      • IPFS Migrator
    • Storage SDK
  • Gateways
    • IPFS Gateway
    • IC Gateway
    • Arweave Gateway
    • Dedicated Gateways
      • Gateway Access Controls
      • Video Streaming
      • IPFS Image Optimizer
    • IPNS Manager
      • IPNS Manager API
  • RPC
    • Guides
    • API Keys
    • JSON Web Token (JWT)
    • What's CUs/CUPS
    • WebSockets
    • Archive Node
    • Debug API
    • Chains RPC
      • BSC / opBNB
      • Ethereum
      • Optimism
      • Polygon
      • Taiko
  • AI
    • AI RPC
      • Quick Start
      • Models
      • API Keys
      • Requests & Responses
      • Parameters
    • 4EVER Chat
  • RaaS - Beta
    • What's Rollups?
    • 4EVER Rollup Stack
  • DePIN
    • 4EVER Network
    • Storage Nodes
  • More
    • Use Cases
      • Livepeer
      • Lens Protocol
      • Optopia.ai
      • Linear Finance
      • Snapshot
      • Tape
      • Taiko
      • Hey.xyz
      • SyncSwap
    • Community
    • Tutorials
    • Security
    • 4EVERLAND FAQ
Powered by GitBook
On this page
  • Requests
  • Request Body
  • Request Headers
  • Responses
  • Response Body
  1. AI
  2. AI RPC

Requests & Responses

Last updated 10 months ago

Requests

Request Body

The request schema, represented as a TypeScript type, serves as the body of the POST request to the /api/v1/chat/completions endpoint. An example of this can be found in the above.

type Request = {
  // Either "messages" or "prompt" is required
  messages?: Message[];
  prompt?: string;
  model?: string; 
  response_format?: { type: 'json_object' };
  stop?: string | string[];
  stream?: boolean; 
  max_tokens?: number; 
  temperature?: number; 
  top_p?: number; 
  top_k?: number; 
  frequency_penalty?: number; 
  presence_penalty?: number; 
  repetition_penalty?: number; 
  seed?: number; 
  tools?: Tool[];
  tool_choice?: ToolChoice;
  // Additional optional parameters
  logit_bias?: { [key: number]: number };
  transforms?: string[];
  models?: string[];
  route?: 'fallback';
  provider?: ProviderPreferences;
};
type TextContent = {
  type: 'text';
  text: string;
};
type ImageContentPart = {
  type: 'image_url';
  image_url: {
    url: string; // URL or base64 encoded image data
    detail?: string; // Optional, defaults to 'auto'
  };
};
type ContentPart = TextContent | ImageContentPart;
type Message = {
  role: 'user' | 'assistant' | 'system' | 'tool';
  content: string | ContentPart[];
  name?: string;
};
type FunctionDescription = {
  description?: string;
  name: string;
  parameters: object; 
type Tool = {
  type: 'function';
  function: FunctionDescription;
};
type ToolChoice =
  | 'none'
  | 'auto'
  | {
      type: 'function';
      function: {
        name: string;
      };
    };

Request Headers

fetch("https://ai.api.4everland.org/api/v1/chat/completions", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${YOUR_API_KEY}`,
    "HTTP-Referer": `${YOUR_SITE_URL}`, // Optional
    "X-Title": `${YOUR_SITE_NAME}`, // Optional
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "model": "mistralai/mixtral-8x7b-instruct",
    "messages": [
      {"role": "user", "content": "Who are you?"},
    ],
  })
});

Responses

4EVERLAND streamlines the schema across various models and providers, thereby requiring the learning of only one schema.

Response Body

It's important to note that the finish_reason may vary depending on the model provider. The model property provides information about the model used within the underlying API.

Here's the response schema, represented as a TypeScript type:

type Response = {
  id: string;
  // Depending on whether you set "stream" to "true" and
  // whether you passed in "messages" or a "prompt", you
  // will get a different output shape
  choices: (NonStreamingChoice | StreamingChoice | NonChatChoice | Error)[];
  created: number; // Unix timestamp
  model: string;
  object: 'chat.completion' | 'chat.completion.chunk';
  // For non-streaming responses only. For streaming responses,
  // see "Querying Cost and Stats" below.
  usage?: {
    completion_tokens: number; // Equivalent to "native_tokens_completion" in the /generation API
    prompt_tokens: number; // Equivalent to "native_tokens_prompt"
    total_tokens: number; // Sum of the above two fields
    total_cost: number; // Number of credits used by this generation
  };
};
// Subtypes:
type NonChatChoice = {
  finish_reason: string | null;
  text: string;
};
type NonStreamingChoice = {
  finish_reason: string | null; // Depends on the model. Ex: 'stop' | 'length' | 'content_filter' | 'tool_calls' | 'function_call'
  message: {
    content: string | null;
    role: string;
    tool_calls?: ToolCall[];
    // Deprecated, replaced by tool_calls
    function_call?: FunctionCall;
  };
};
type StreamingChoice = {
  finish_reason: string | null;
  delta: {
    content: string | null;
    role?: string;
    tool_calls?: ToolCall[];
    // Deprecated, replaced by tool_calls
    function_call?: FunctionCall;
  };
};
type Error = {
  code: number; // See "Error Handling" section
  message: string;
};
type FunctionCall = {
  name: string;
  arguments: string; // JSON format arguments
};
type ToolCall = {
  id: string;
  type: 'function';
  function: FunctionCall;
};

Here's an example:

json
{
  "id": "gen-xxxxxxxxxxxxxx",
  "choices": [
    {
      "finish_reason": "stop", // Different models provide different reasons here
      "message": {
        // will be "delta" if streaming
        "role": "assistant",
        "content": "Hello there!"
      }
    }
  ],
  "model": "openai/gpt-3.5-turbo" // Could also be "anthropic/claude-2.1", etc, depending on the "model" that ends up being used
}

The responses align closely with the , ensuring that choices are always presented as an array, even when the model returns only one completion. Each choice will include a delta property if a stream was requested, and a message property otherwise. This design simplifies the code usage across all models.

Quick Start
OpenAI Chat API