PiAPI
HomeWorkspace
HomeWorkspace
Join Discord
  1. LLM
  • Get Started
    • Overview
    • Quickstart
    • Make Instruction: How to Use PiAPI to Build a Workflow on Make?
  • Endpoints
    • Song(Udio)
      • Song API Task Creation Examples
      • [Udio] Song Extend
      • Get Task
      • Create Task
      • [Udio] Generate Lyrics
    • Kling
      • Lipsync With PiAPI Kling API Examples
      • Motion Brush With PiAPI Kling API Example
      • Kling Elements Video Generation API
      • Kling Effects Video Generation
      • Cancel Task
        • Cancel Tasks
        • Cancel Task
      • Get Task
      • Create Task
      • Kling Virtual Try-On
    • Hailuo
      • Hailuo Director Mode Example
      • Generate Video
      • Get Task
    • Flux
      • Flux with LoRA and Controlnet
      • Available LoRA and Controlnet
      • Flux API with Redux Variation, Fill, Inpaint and Outpaint
      • Create Task
        • Text to Image
        • Image to Image
      • Get task
    • AI Hug
      • Get Task
      • Create Task
    • LLM
      • Use Cases for GPT-4o Image API
      • How To Avoid Timeouts in Completion API
      • GPT-4o Image Generation API
      • LLM API | Basic Completions
        POST
      • Get Task
        GET
    • Midjourney
      • PiAPI Penalties on Midjourney Usage
      • Detailed Explaination on Midjourney Task Result
      • Midjourney V7 API Instructions
      • Create Task
        • Imagine
        • Upscale
        • Variation
        • Reroll
        • Describe
        • Seed
        • Blend
        • Inpaint
        • Outpaint
        • Pan
      • Cancel Task
        • Cancel Task
        • Cancel Tasks
      • Get Task
    • Faceswap
      • Multi Faceswap
      • Image Faceswap
      • Video Faceswap
      • Get Task
    • TTS
      • Zeroshot Text-to-Speech F5-TTS
      • Get Task
    • Trellis
      • Create Task
      • Get Task
    • Luma Dream Machine
      • Cancel Task
        • Cancel Tasks
        • Cancel Task
      • Create Task
      • Get Task
    • WanX
      • Available LoRA Types for Wanx
      • Generate WanX Task with LoRA Using PiAPI
      • Use Cases for Wanx LoRA
      • Create Task
      • Get Task
    • Skyreels
      • Create Task
      • Get Task
    • Framepack
      • Create Task
      • Get Task
    • Hunyuan Video
      • How to Make a Hunyuan API Call
      • Get Task
      • Generate Video
    • Mmaudio
      • Get Task
      • Generate Audio
    • DiffRhythm
      • Generate Audio
      • Get Task
    • Tools
      • File Upload API
      • Video Upscale
      • Video Upscale-Get Task
      • Remove Background API
      • Remove Background-Get Task
      • Segment With Prompt API
      • Segment With Prompt API-Get Task
      • Image Upscale(Super Resolution) API
      • Image Upscale-Get Task
    • PiAPI Account Management
      • PiAPI Account Info
      • Task List Info
      • User Task History
  • Resources
    • Change Log
    • Output Storage
    • Unified API Schema
    • Webhook
    • Bulk Generation Service
    • Billings
    • PiAPI MCP Server
    • Workspace Manual
      • Host-your-account (HYA) | Back-up Account
      • Host-your-account (HYA) | Debug Checklist
      • Host-your-account (HYA) | Connected Account Status
    • Announcements
      • PiAPI 2025 January 1st Pricing Update
  • Legacy Documentation
    • Midjourney
      • Midjourney Webhook
      • Imagine
      • Reroll
      • Upscale
      • Variation
      • Inpaint
      • Outpaint
      • Pan
      • Describe
      • Blend
      • Seed
      • Fetch
      • Multi Fetch
      • Cancel
    • Face Swap
      • Video Faceswap
      • Multi-face-swap
      • Fetch
    • Dream Machine
      • Video Generation
      • Video Extend
      • Get Video Generation
    • Kling
      • Video Generation
      • Video Extend
      • Get Video Generation
  1. LLM

LLM API | Basic Completions

POST
/v1/chat/completions
LLM
INFO

Discount#

PiAPI also provides different LLM API at cost effective pricing, sometimes at 25%~75% of their official pricing.

Availability#

Given the steep discount, we sometimes face availability issues thus we always recommend developers to always have another back up API source ready - take advantage of our low pricing when you can, and when availability becomes a problem switch to a higher cost solution to maintain overall system up-time.


model namepricingNotes
gpt-4o-miniinput 1M tokens = $0.1125
output 1M tokens = $0.45
75% of OpenAI's official pricing
gpt-4oinput 1M tokens = $1.875
output 1M tokens = $7.5
Only for Creator Plan or Above
75% of OpenAI's official pricing, as the original OpenAI's API model gpt-4o.
gpt-4.1 and gpt-4.1-mini and gpt-4.1 nano75% of OpenAI's official pricing, as the original OpenAI's API75% of OpenAI's official pricing, as the original OpenAI's API
claude-3-7-sonnet-20250219input 1M tokens = $2.25
output 1M tokens = $11.25
Only for Creator Plan or Above
75% of Anthropic's official pricing
gpt-4o-image$0.02 per requestsee 4o image generation api
gpt-image-1same as openai officialsee openai-official-pricing
Note:
1.
OpenAI's input and output tokens, where 1k token roughly equals to 750 words. Thus 1 token roughly equates to 0.75 word.
2.
The definition of minimum charge: if the actual token (input+output) usage for that particular completion is less than that value, we will round it that value.

Request

Header Params
Authorization
string 
required
Your API KEY for authorization
Body Params application/json
model
string 
required
The name of the model to be used

How to get Gizmo model name: Go to ChatGPT official website, explore the GPTs and enter chat with the GPT of your choice, you will see webpage address like https://chatgpt.com/g/g-gFt1ghYJl-logo-creator. Then the model name you should use is gpt-4-gizmo-g-gFt1ghYJl.
messages
array[string]
required
A list of messages comprising the conversation so far
functions
array[string]
optional
A list of functions the model may generate JSON inputs for.
function_call
string 
optional
Controls how the model calls functions.

"none" means the model will not call a function and instead generates a message.

"auto" means the model can pick between generating a message or calling a function.

Specifying a particular function via {name:my_function} forces the model to call that function.

"none" is the default when no functions are present.

"auto" is the default if functions are present.
temperature
number 
optional
Defaults to 1. What sampling temperature to use, between 0 and 2.

Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
top_p
number 
optional
Defaults to 1.

An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass.

So 0.1 means only the tokens comprising the top 10% probability mass are considered.
n
integer 
optional
Defaults to 1.

How many chat completion choices to generate for each input message.
stream
boolean 
optional
Defaults to false.

If set, partial message deltas will be sent, like in ChatGPT.

Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data:[none] message
stop
string  | array
optional
Defaults to null.

Up to 4 sequences where the API will stop generating further tokens.
max_tokens
number 
optional
Defaults to the maximum number of tokens to generate in the chat completion.
presence_penalty
number 
optional
Defaults to 0.

Number between -2.0 and 2.0.

Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
frequency_penalty
number 
optional
Defaults to 0.

Number between -2.0 and 2.0.

Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
logit_bias
string 
optional
Defaults to null. Modify the likelihood of specified tokens appearing in the completion.
Example
//Request Example - No Streaming

curl https://api.piapi.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer API_KEY" \
  -d '{
    "model": "gpt-3.5-turbo",
    "messages": [
     {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Hello!"
      }
    ]
  }'


  //Request Example - Streaming
  curl https://api.piapi.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer API_KEY" \
  -d '{
    "model": "gpt-3.5-turbo",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Hello!"
      }
   ],
    "stream": true
  }'

Request samples

Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
Request Request Example
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://api.piapi.ai/v1/chat/completions' \
--header 'Authorization;' \
--header 'Content-Type: application/json' \
--data-raw '//Request Example - No Streaming

curl https://api.piapi.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer API_KEY" \
  -d '\''{
    "model": "gpt-3.5-turbo",
    "messages": [
     {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Hello!"
      }
    ]
  }'\''


  //Request Example - Streaming
  curl https://api.piapi.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer API_KEY" \
  -d '\''{
    "model": "gpt-3.5-turbo",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Hello!"
      }
   ],
    "stream": true
  }'\'''

Responses

🟢200OK
application/json
Body
id
string 
required
object
string 
required
created
integer 
required
model
string 
required
choices
array [object {3}] 
required
index
integer 
optional
message
object 
optional
finish_reason
string 
optional
usage
object 
required
prompt_tokens
integer 
required
completion_tokens
integer 
required
total_tokens
integer 
required
Examples
{
  "id": "chatcmpl-83jZ61GDHtdlsFUzXDbpGeoU193Mj",
  "object": "chat.completion",
  "created": 1695900828,
  "model": "gpt-3.5-turbo",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I assist you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 19,
    "completion_tokens": 9,
    "total_tokens": 28
  }
}
🟠400Bad Request
🟠401Unauthorized
🔴500Server Error
Modified at 2025-04-28 11:13:18
Previous
GPT-4o Image Generation API
Next
Get Task