免費體驗 Grok 4 API,用於大模型推理、寫作、程式協助、分析和摘要。為生產 AI 工作流程提供穩定的 xAI 存取能力。適合專業團隊在 AI 工作流程中處理應用整合、協作交付、場景驗證、內容複核、資料整理、業務分析、多步驟任務、產品探索與日常團隊迭代,持續建置、測試、驗證、最佳化並改進 AI 功能體驗。穩定接入 GPT、Claude 等 LLM API,用於 AI Agent、聊天機器人、研究、程式碼、自動化與智慧應用。
Grok 4 相關模型
API 範例
提交範例
const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
Accept: 'text/event-stream',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'grok-4-text-to-text',
messages: [
{
role: 'user',
content: 'Explain the key differences between REST and GraphQL APIs.'
}
],
stream: true,
max_tokens: 2048
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
let buffer = '';
let assistantText = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const frames = buffer.split('\n\n');
buffer = frames.pop() || '';
for (const frame of frames) {
const lines = frame.split('\n').filter(Boolean);
let eventName = 'message';
const dataLines = [];
for (const line of lines) {
if (line.startsWith('event:')) {
eventName = line.slice(6).trim();
} else if (line.startsWith('data:')) {
dataLines.push(line.replace(/^data:\s*/, ''));
}
}
const raw = dataLines.join('\n').trim();
if (raw === '[DONE]') {
console.log('\nFinal text:', assistantText);
continue;
}
let payload;
try {
payload = JSON.parse(raw);
} catch {
continue;
}
if (eventName === 'error' || payload.error) {
const msg = payload.error?.message ?? payload.message ?? 'Chat request failed';
throw new Error(msg);
}
const delta = payload.choices?.[0]?.delta;
if (delta?.content) {
assistantText += delta.content;
console.log(assistantText);
}
}
}
提交範例
import json
import requests
response = requests.post(
'https://api.flaq.ai/api/v1/chat/completions',
headers={
'Authorization': 'Bearer YOUR_API_KEY',
'Accept': 'text/event-stream',
'Content-Type': 'application/json',
},
json={
'model': 'grok-4-text-to-text',
'messages': [
{
'role': 'user',
'content': 'Explain the key differences between REST and GraphQL APIs.',
}
],
'stream': True,
'max_tokens': 2048,
},
stream=True,
)
response.raise_for_status()
event_name = 'message'
assistant_text = ''
for raw_line in response.iter_lines(decode_unicode=True):
if not raw_line:
event_name = 'message'
continue
if raw_line.startswith('event:'):
event_name = raw_line.replace('event:', '', 1).strip()
continue
if raw_line.startswith('data:'):
raw_data = raw_line.replace('data:', '', 1).strip()
if raw_data == '[DONE]':
print('\nFinal text:', assistant_text)
continue
payload = json.loads(raw_data)
if event_name == 'error' or payload.get('error'):
error = payload.get('error') or payload
raise RuntimeError(error.get('message', 'Chat request failed'))
choices = payload.get('choices') or []
if choices:
delta = choices[0].get('delta') or {}
content = delta.get('content')
if content:
assistant_text += content
print(content, end='', flush=True)
提交範例
curl -N -X POST "https://api.flaq.ai/api/v1/chat/completions" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Accept: text/event-stream" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4-text-to-text",
"messages": [
{
"role": "user",
"content": "Explain the key differences between REST and GraphQL APIs."
}
],
"stream": true,
"max_tokens": 2048
}'
Grok 4 Text to Text 價格
| 參數 | 價格 | 原價 | 折扣 |
|---|
README
快速且實惠的 Grok 4 Text-to-Text API(xAI 的進階語言模型)
Flaq AI 上的 Grok 4 Text-to-Text API 提供 xAI 模型存取,適用於需要可靠推理、對話式輸出與 production 就緒整合的專業語言工作流程。這個 Grok API 路由可協助開發者打造聊天、寫作、分析、程式開發與自動化功能,並提供彈性的對話情境與實用的輸出控制。它專為想要受管理 xAI 文字能力、且不想處理供應商專屬基礎設施的團隊而設計。
Grok 4 Text-to-Text API 的主要功能
- 進階文字推理: 以強大的語言理解處理複雜 prompt、說明、寫作任務與程式開發協助。
- 對話式輸出: 建立可維持有用情境並支援後續精修的聊天體驗。
- 可靠的指令遵循: 將結構化需求轉換為清楚回答、摘要、草稿與實用輸出。
- 彈性的 API 控制: 透過 Flaq AI 上的實用設定,引導回應長度、風格與任務方向。
- 高性價比整合: 透過受管理 API 路由加入 Grok 文字能力,並具備可預測的 production 行為。
- 開發者友善工作流程: 透過穩定模型路由與清楚輸入模式,快速從原型推進到 production。
如何在 Flaq AI 上使用 Grok 4 Text-to-Text API 進行文字生成
- 輸入: 自然語言 prompt、系統指令、對話情境與結構化任務需求。
- 輸出: 透過 Flaq AI 上穩定的 chat API 整合提供高品質文字回應。
- 路由設定: 專為具備彈性情境與後續追問支援的對話式文字工作流程而設計。
- 設定: 支援回應長度與任務方向的實用輸出控制。
- 能力: 透過 xAI Grok API 整合提供聊天協助、寫作、摘要、程式開發協助、腦力激盪、結構化輸出規劃與對話式自動化。
Grok 4 Text-to-Text API 整合的最佳使用場景
- AI 聊天助理: 為應用程式、產品與內部工具建立即時對話體驗。
- 內容與寫作工作流程: 以一致結構起草文章、摘要、大綱、電子郵件與社群內容。
- 開發者生產力: 說明程式碼、撰寫片段、摘要技術細節,並支援工程工作流程。
- 研究與分析: 將 prompt 與來源情境轉換為實用比較、簡報與建議。
- 商務自動化: 將語言智慧加入儀表板、支援工具與營運工作流程。
注意 請確保 prompt 與應用程式工作流程符合 xAI 的安全與使用準則。如果發生錯誤,請檢查輸入是否含有限制內容、簡化請求,然後再試一次。
Grok 4 Text-to-Text 與競品比較:比較分析
-
Grok 4 vs. GPT Models
GPT models 提供 OpenAI 原生行為與廣泛的生態熟悉度。Grok 4 為團隊提供 xAI 路由,用於受管理的文字生成與對話式產品功能。 -
Grok 4 vs. Claude Opus
Claude Opus 在細緻寫作與複雜分析方面表現強大。Grok 4 為想在 Flaq AI 上使用彈性聊天與 text-to-text 工作流程的團隊提供 xAI 替代選擇。 -
Grok 4 vs. Gemini
Gemini models 對 Google 原生使用場景很有吸引力。Grok 4 專注於 xAI 模型行為,以及透過穩定 API 路由提供受管理文字生成。 -
Grok 4 vs. Qwen
Qwen models 提供強大的 Alibaba 語言工作流程與多語價值。Grok 4 適合想在模型組合中加入 xAI 驅動文字生成的團隊。 -
Grok 4 vs. Llama
Llama models 讓開發者掌握開放模型部署控制。Grok 4 移除託管複雜度,並為 production 文字功能提供受管理的 API 存取。