1For AI
  • Welcome
  • Getting Started
    • Quickstart
  • Model
    • Retrieve Model List
    • Get Single Model
  • Chat
    • Create new chat
    • Continue Chat Conversation
  • User
    • User Balance
  • Errors
    • Common Errors
Powered by GitBook
On this page
  1. Chat

Create new chat

API Documentation: Create Chat Completion

Endpoint

POST /v1/chat/completions

Description

This endpoint creates a chat completion based on a conversation between the user and the AI model.

Request

cURL Example:

curl --location 'https://api.1for.ai/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header 'api-key: {API_KEY}' \
--data '{
  "model": "auto",
  "messages": [
    {"role": "user", "content": "How are you doing today?"}
  ]
}'

Replace {API_KEY} with your actual API key.

Request Body:

  • messages: (array) A list of message objects with:

    • role: (string) "user" or "system".

    • content: (string) The text content of the message.

Response

The response will be a JSON object containing the AI's reply and metadata:

{
    "text": String,
    "cost": Double,
    "role": "system",
    "chat_id": String,
    "model": String
}
  • text: The generated text response.

  • cost: The amount charged for this interaction.

  • role: The role from which the response originates (typically "system").

  • chat_id: A unique identifier for the conversation session. can be user later to continue conversation for that topic.

  • model: The name of the model used to generate the completion.

Notes

  • Ensure you send valid JSON in your request body.

  • Costs depend on model usage and token counts.

  • Using "model": "auto" allows automatic selection based on request text you send.

PreviousGet Single ModelNextContinue Chat Conversation

Last updated 1 month ago

model: (string) Model name to use. Use "auto" for automatic selection. or choose from

here