- Introduction
- Quick Start Guide
- Make a request
- Chat Models
- ChatGpt
- ChatGPT (Audio)
- ChatGPT (Chat)
- Chat completion object
- Create chat completion (streaming)
- Create chat completion (non-streaming)
- Create chat image recognition (streaming)
- Create chat image recognition (streaming) base64
- Create chat image recognition (non-streaming)
- Function calling
- N choices
- Create chat function call (only non-streaming)
- Create structured output
- ChatGPT (Completions)
- ChatGPT(Embeddings)
- Anthropic Claude
- Gemini
- Image Models
- GPT-IMAGE-1
- MJ
- Ideogram
- Kling Image
- Flux
- Recraft API
- Models use Dall-e Format
- DALL·E 3POST
- Video Models
- Kling Video
- Runway ML Video
- Luma Video
- Pika Video
- Google Veo
- Minimax - Hailuo
- Music Model - Suno
- Illustrate
- Parameter
- Task submission
- Query interface
- Python Samples
- python openai official library (using AutoGPT, langchain, etc.)
- Python uses speech to text
- Python uses text to speech
- Python uses Embeddings
- python calls DALL·E
- python simple call openai function-calling demo
- python langchain
- python llama_index
- Python uses gpt-4o to identify pictures-local pictures
- python library streaming output
- Python uses gpt-4o to identify images
- Plug-in/software usage tutorials
- Help Center
- Tutorials
Function calling - codeExecution
POST
/v1/chat/completions
Request
Header Params
Content-Type
string
required
Example:
application/json
Accept
string
required
Example:
application/json
Authorization
string
optional
Example:
Bearer {{YOUR_API_KEY}}
Body Params application/json
model
string
required
messages
array [object {2}]
required
role
string
optional
content
string
optional
temperature
integer
optional
top_p
integer
optional
temperature
but not both.n
integer
optional
How many chat completion choices are generated for each input message.
stream
boolean
optional
stop
string
optional
max_tokens
integer
optional
The maximum number of tokens generated in chat completion.
presence_penalty
number
optional
frequency_penalty
number
optional
logit_bias
null
optional
user
string
optional
response_format
object
optional
seen
integer
optional
tools
array[string]
required
tool_choice
object
required
Example
{
"model": "gemini-2.5-flash-preview-05-20",
"messages": [
{
"role": "user",
"content": "Viết một đoạn mã Python in ra dãy số Fibonacci và thực thi nó."
}
],
"tools": [
{
"type": "function",
"function": {
"name": "codeExecution"
}
}
],
"tool_choice": "auto"
}
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 '/v1/chat/completions' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {{YOUR_API_KEY}}' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "gemini-2.5-flash-preview-05-20",
"messages": [
{
"role": "user",
"content": "Viết một đoạn mã Python in ra dãy số Fibonacci và thực thi nó."
}
],
"tools": [
{
"type": "function",
"function": {
"name": "codeExecution"
}
}
],
"tool_choice": "auto"
}'
Responses
🟢200OK
application/json
Body
id
string
required
model
string
required
object
string
required
created
integer
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
prompt_tokens_details
object
required
completion_tokens_details
object
required
input_tokens
integer
required
output_tokens
integer
required
input_tokens_details
null
required
Example
{
"id": "chatcmpl-77f44a3e57914777b21e141dd05296d1",
"model": "gemini-2.5-flash-preview-05-20",
"object": "chat.completion",
"created": 1748165257,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Chắc chắn rồi. Dưới đây là đoạn mã Python để in ra dãy số Fibonacci. Tôi sẽ viết một hàm để tạo các số Fibonacci và sau đó gọi nó để in ra.\n\nĐoạn mã này sẽ in 10 số đầu tiên của dãy Fibonacci.\n\n\n```PYTHON\ndef fibonacci_sequence(n):\n \"\"\"\n In ra n số đầu tiên của dãy Fibonacci.\n \"\"\"\n a, b = 0, 1\n count = 0\n fib_list = []\n\n if n <= 0:\n print(\"Vui lòng nhập một số nguyên dương.\")\n elif n == 1:\n fib_list.append(a)\n else:\n while count < n:\n fib_list.append(a)\n nth = a + b\n a = b\n b = nth\n count += 1\n return fib_list\n\n# In ra 10 số đầu tiên của dãy Fibonacci\nnum_terms = 10\nfib_series = fibonacci_sequence(num_terms)\nprint(f\"Dãy Fibonacci gồm {num_terms} số đầu tiên:\")\nprint(fib_series)\n\n\n```\n```output\nDãy Fibonacci gồm 10 số đầu tiên:\n[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]\n\n```\nĐoạn mã trên:\n1. Định nghĩa một hàm `fibonacci_sequence(n)` nhận một số nguyên `n` làm đối số, đại diện cho số lượng số Fibonacci cần tạo.\n2. Khởi tạo hai biến `a` và `b` với các giá trị ban đầu là 0 và 1 (hai số đầu tiên của dãy Fibonacci).\n3. Sử dụng vòng lặp `while` để tạo ra các số Fibonacci cho đến khi đạt được `n` số.\n4. Mỗi lần lặp, nó thêm số hiện tại (`a`) vào danh sách `fib_list`, sau đó tính số Fibonacci tiếp theo bằng cách cộng `a` và `b`, và cập nhật `a` và `b` cho lần lặp tiếp theo.\n5. Cuối cùng, nó gọi hàm với `num_terms = 10` để in ra 10 số đầu tiên của dãy."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 17,
"completion_tokens": 998,
"total_tokens": 1015,
"prompt_tokens_details": {
"cached_tokens": 0,
"text_tokens": 0,
"audio_tokens": 0,
"image_tokens": 0
},
"completion_tokens_details": {
"text_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 123
},
"input_tokens": 0,
"output_tokens": 0,
"input_tokens_details": null
}
}
Modified at 2025-05-25 09:35:51