推理 API
模型
GET /v1/models
列出对认证 API 密钥可用的所有模型,包括模型名称(ID)、创建时间和定价。
响应体
data(array<object>, 必需) — 包含简化信息的模型列表。aliases(array<string>, 必需) — 用户可在请求的模型字段中使用的模型别名 ID。cached_prompt_text_token_price(integer | null) — 之前缓存的提示文本 token 的价格(以美元/亿 tokens 计)。cached_prompt_text_token_price_long_context(integer | null) — 长上下文请求的缓存提示文本 token 价格(以美元/亿 tokens 计)。completion_text_token_price(integer | null) — 完成文本 token 的价格(以美元/亿 tokens 计)。completion_text_token_price_long_context(integer | null) — 长上下文请求的完成文本 token 价格(以美元/亿 tokens 计)。context_length(integer | null) — 模型支持的最大上下文长度(以 tokens 计)。created(integer, 必需) — 模型创建时间的 Unix 时间戳。id(string, 必需) — 模型 ID。可从 https://console.x.ai/team/default/models 或 https://docs.x.ai/docs/models 获取。image_price(integer | null) — 每张图像的价格(以美元分计)(图像生成模型)。long_context_threshold(integer | null) — 长上下文价格适用的 token 数量阈值。object(string, 必需) — 对象类型,始终为"model"。owned_by(string, 必需) — 模型所有者。prompt_image_token_price(integer | null) — 提示图像 token 的价格(以美元/亿 tokens 计)。prompt_text_token_price(integer | null) — 提示文本 token 的价格(以美元/亿 tokens 计)。prompt_text_token_price_long_context(integer | null) — 长上下文请求的提示文本 token 价格(以美元/亿 tokens 计)。
object(string, 必需) —data字段的对象类型,始终为"list"。
响应示例:
{
"data": [
{
"id": "latest",
"aliases": [],
"context_length": 131072,
"created": 1776556800,
"object": "model",
"owned_by": "xai",
"prompt_text_token_price": 12500,
"cached_prompt_text_token_price": 2000,
"prompt_image_token_price": 12500,
"completion_text_token_price": 25000
},
{
"id": "grok-420-reasoning",
"aliases": [],
"context_length": 256000,
"created": 1768003200,
"object": "model",
"owned_by": "xai",
"prompt_text_token_price": 20000,
"cached_prompt_text_token_price": 2000,
"prompt_image_token_price": 0,
"completion_text_token_price": 80000,
"prompt_text_token_price_long_context": 40000,
"completion_text_token_price_long_context": 160000,
"long_context_threshold": 128000
},
{
"id": "grok-imagine-image",
"aliases": [],
"context_length": 1024,
"created": 1769472000,
"object": "model",
"owned_by": "xai",
"image_price": 200000000
}
],
"object": "list"
}GET /v1/models/
获取带有 model_id 的模型信息,包括定价。
路径参数
model_id(string, 必需) — 要获取的模型 ID。
响应体
aliases(array<string>, 必需) — 用户可在请求的模型字段中使用的模型别名 ID。cached_prompt_text_token_price(integer | null) — 之前缓存的提示文本 token 的价格(以美元/亿 tokens 计)。cached_prompt_text_token_price_long_context(integer | null) — 长上下文请求的缓存提示文本 token 价格(以美元/亿 tokens 计)。completion_text_token_price(integer | null) — 完成文本 token 的价格(以美元/亿 tokens 计)。completion_text_token_price_long_context(integer | null) — 长上下文请求的完成文本 token 价格(以美元/亿 tokens 计)。context_length(integer | null) — 模型支持的最大上下文长度(以 tokens 计)。created(integer, 必需) — 模型创建时间的 Unix 时间戳。id(string, 必需) — 模型 ID。可从 https://console.x.ai/team/default/models 或 https://docs.x.ai/docs/models 获取。image_price(integer | null) — 每张图像的价格(以美元分计)(图像生成模型)。long_context_threshold(integer | null) — 长上下文价格适用的 token 数量阈值。object(string, 必需) — 对象类型,始终为"model"。owned_by(string, 必需) — 模型所有者。prompt_image_token_price(integer | null) — 提示图像 token 的价格(以美元/亿 tokens 计)。prompt_text_token_price(integer | null) — 提示文本 token 的价格(以美元/亿 tokens 计)。prompt_text_token_price_long_context(integer | null) — 长上下文请求的提示文本 token 价格(以美元/亿 tokens 计)。
响应示例:
{
"id": "latest",
"created": 1776556800,
"object": "model",
"owned_by": "xai",
"prompt_text_token_price": 12500,
"cached_prompt_text_token_price": 2000,
"prompt_image_token_price": 12500,
"completion_text_token_price": 25000
}GET /v1/language-models
列出对认证 API 密钥可用的所有聊天和图像理解模型及其完整信息。与 /v1/models 相比,额外信息包括模态、指纹和别名。
响应体
models(array<object>, 必需) — 可用语言模型数组。aliases(array<string>, 必需) — 用户可在请求的模型字段中使用的模型别名 ID。cached_prompt_text_token_price(integer, 必需) — 之前缓存的提示文本 token 的价格(以美元/亿 tokens 计)。cached_prompt_text_token_price_long_context(integer, 必需) — 长上下文请求的缓存提示文本 token 价格(以美元/亿 tokens 计)。 当为 0 时,回退到 cached_prompt_text_token_price。completion_text_token_price(integer, 必需) — 完成文本 token 的价格(以美元/亿 tokens 计)。completion_text_token_price_long_context(integer, 必需) — 长上下文请求的完成文本 token 价格(以美元/亿 tokens 计)。 当为 0 时,应用标准的 completion_text_token_price。created(integer, 必需) — 模型创建时间的 Unix 时间戳。fingerprint(string, 必需) — 托管模型的 xAI 系统配置的指纹。id(string, 必需) — 模型 ID。可从 https://console.x.ai/team/default/models 或 https://docs.x.ai/docs/models 获取。input_modalities(array<string>, 必需) — 模型支持的输入模态,例如"text"、"image"。long_context_threshold(integer, 必需) — 长上下文价格适用的 token 数量阈值。 当为 0 时,模型没有长上下文定价层级。object(string, 必需) — 对象类型,始终为"model"。output_modalities(array<string>, 必需) — 模型支持的输出模态,例如"text"、"image"。owned_by(string, 必需) — 模型所有者。prompt_image_token_price(integer, 必需) — 提示图像 token 的价格(以美元/亿 tokens 计)。prompt_text_token_price(integer, 必需) — 提示文本 token 的价格(以美元/亿 tokens 计)。prompt_text_token_price_long_context(integer, 必需) — 长上下文请求的提示文本 token 价格(以美元/亿 tokens 计)。 当为 0 时,所有上下文长度都应用标准的 prompt_text_token_price。search_price(integer, 必需) — 搜索的价格(以美元/亿次搜索计)。version(string, 必需) — 模型版本。
响应示例:
{
"models": [
{
"id": "latest",
"fingerprint": "fp_777a9f8466",
"created": 1776556800,
"object": "model",
"owned_by": "xai",
"version": "1.0",
"input_modalities": [
"text",
"image"
],
"output_modalities": [
"text"
],
"prompt_text_token_price": 12500,
"cached_prompt_text_token_price": 2000,
"prompt_image_token_price": 12500,
"completion_text_token_price": 25000,
"search_price": 0,
"prompt_text_token_price_long_context": 0,
"cached_prompt_text_token_price_long_context": 0,
"completion_text_token_price_long_context": 0,
"long_context_threshold": 0,
"aliases": [
"grok-4.3-latest",
"grok-latest"
]
},
{
"id": "grok-420-reasoning",
"fingerprint": "fp_5319828d69",
"created": 1768003200,
"object": "model",
"owned_by": "xai",
"version": "1.0",
"input_modalities": [
"text"
],
"output_modalities": [
"text"
],
"prompt_text_token_price": 20000,
"cached_prompt_text_token_price": 2000,
"prompt_image_token_price": 0,
"completion_text_token_price": 80000,
"search_price": 0,
"prompt_text_token_price_long_context": 40000,
"cached_prompt_text_token_price_long_context": 0,
"completion_text_token_price_long_context": 160000,
"long_context_threshold": 128000,
"aliases": []
}
]
}GET /v1/language-models/
获取带有 model_id 的聊天或图像理解模型的完整信息。
路径参数
model_id(string, 必需) — 要获取的模型 ID。
响应体
aliases(array<string>, 必需) — 用户可在请求的模型字段中使用的模型别名 ID。cached_prompt_text_token_price(integer, 必需) — 之前缓存的提示文本 token 的价格(以美元/亿 tokens 计)。cached_prompt_text_token_price_long_context(integer, 必需) — 长上下文请求的缓存提示文本 token 价格(以美元/亿 tokens 计)。 当为 0 时,回退到 cached_prompt_text_token_price。completion_text_token_price(integer, 必需) — 完成文本 token 的价格(以美元/亿 tokens 计)。completion_text_token_price_long_context(integer, 必需) — 长上下文请求的完成文本 token 价格(以美元/亿 tokens 计)。 当为 0 时,应用标准的 completion_text_token_price。created(integer, 必需) — 模型创建时间的 Unix 时间戳。fingerprint(string, 必需) — 托管模型的 xAI 系统配置的指纹。id(string, 必需) — 模型 ID。可从 https://console.x.ai/team/default/models 或 https://docs.x.ai/docs/models 获取。input_modalities(array<string>, 必需) — 模型支持的输入模态,例如"text"、"image"。long_context_threshold(integer, 必需) — 长上下文价格适用的 token 数量阈值。 当为 0 时,模型没有长上下文定价层级。object(string, 必需) — 对象类型,始终为"model"。output_modalities(array<string>, 必需) — 模型支持的输出模态,例如"text"、"image"。owned_by(string, 必需) — 模型所有者。prompt_image_token_price(integer, 必需) — 提示图像 token 的价格(以美元/亿 tokens 计)。prompt_text_token_price(integer, 必需) — 提示文本 token 的价格(以美元/亿 tokens 计)。prompt_text_token_price_long_context(integer, 必需) — 长上下文请求的提示文本 token 价格(以美元/亿 tokens 计)。 当为 0 时,所有上下文长度都应用标准的 prompt_text_token_price。search_price(integer, 必需) — 搜索的价格(以美元/亿次搜索计)。version(string, 必需) — 模型版本。
响应示例:
{
"id": "latest",
"fingerprint": "fp_156d35dcaa",
"created": 1743724800,
"object": "model",
"owned_by": "xai",
"version": "1.0.0",
"input_modalities": [
"text"
],
"output_modalities": [
"text"
],
"prompt_text_token_price": 20000,
"cached_prompt_text_token_price": 0,
"prompt_image_token_price": 0,
"completion_text_token_price": 100000,
"aliases": [
"grok-4",
"grok-4-latest"
]
}GET /v1/image-generation-models
列出对认证 API 密钥可用的所有图像生成模型及其完整信息。与 /v1/models 相比,额外信息包括模态、指纹和别名。
响应体
models(array<object>, 必需) — 可用图像生成模型数组。aliases(array<string>, 必需) — 用户可在请求的模型字段中使用的模型别名 ID。created(integer, 必需) — 模型创建时间的 Unix 时间戳。fingerprint(string, 必需) — 托管模型的 xAI 系统配置的指纹。id(string, 必需) — 模型 ID。image_price(integer, 必需) — 单张图像的价格(以美元分计)。input_modalities(array<string>, 必需) — 模型支持的输入模态。max_prompt_length(integer, 必需)object(string, 必需) — 对象类型,始终为"model"。output_modalities(array<string>, 必需) — 模型支持的输出模态。owned_by(string, 必需) — 模型所有者。version(string, 必需) — 模型版本。
响应示例:
{
"models": [
{
"id": "grok-imagine-image",
"fingerprint": "fp_ca78641a52",
"max_prompt_length": 1024,
"created": 1738961600,
"object": "model",
"owned_by": "xai",
"version": "1.0.0",
"prompt_text_token_price": 100000,
"prompt_image_token_price": 100000,
"generated_image_token_price": 100000,
"aliases": []
}
]
}GET /v1/image-generation-models/
获取带有 model_id 的图像生成模型的完整信息。
路径参数
model_id(string, 必需) — 要获取的模型 ID。
响应体
aliases(array<string>, 必需) — 用户可在请求的模型字段中使用的模型别名 ID。created(integer, 必需) — 模型创建时间的 Unix 时间戳。fingerprint(string, 必需) — 托管模型的 xAI 系统配置的指纹。id(string, 必需) — 模型 ID。image_price(integer, 必需) — 单张图像的价格(以美元分计)。input_modalities(array<string>, 必需) — 模型支持的输入模态。max_prompt_length(integer, 必需)object(string, 必需) — 对象类型,始终为"model"。output_modalities(array<string>, 必需) — 模型支持的输出模态。owned_by(string, 必需) — 模型所有者。version(string, 必需) — 模型版本。
响应示例:
{
"id": "grok-imagine-image",
"fingerprint": "fp_ca78641a52",
"max_prompt_length": 1024,
"created": 1737961600,
"object": "model",
"owned_by": "xai",
"version": "1.0.0",
"prompt_text_token_price": 100000,
"prompt_image_token_price": 100000,
"generated_image_token_price": 100000,
"aliases": []
}GET /v1/video-generation-models
列出对认证 API 密钥可用的所有视频生成模型及其完整信息。
响应体
models(array<object>, 必需) — 可用视频生成模型数组。aliases(array<string>, 必需) — 用户可在请求的模型字段中使用的模型别名 ID。created(integer, 必需) — 模型创建时间的 Unix 时间戳。fingerprint(string, 必需) — 托管模型的 xAI 系统配置的指纹。id(string, 必需) — 模型 ID。input_modalities(array<string>, 必需) — 模型支持的输入模态(例如 "text", "image"; 接受参考音频的模型为 "audio")。object(string, 必需) — 对象类型,始终为"model"。output_modalities(array<string>, 必需) — 模型支持的输出模态(例如 "video")。owned_by(string, 必需) — 模型所有者。version(string, 必需) — 模型版本。
响应示例:
{
"models": [
{
"id": "grok-imagine-video",
"fingerprint": "fp_898ae9f31c",
"created": 1743724800,
"object": "model",
"owned_by": "xai",
"version": "1.0.0",
"input_modalities": [
"text",
"image"
],
"output_modalities": [
"video"
],
"aliases": []
}
]
}GET /v1/video-generation-models/
获取带有 model_id 的视频生成模型的完整信息。
路径参数
model_id(string, 必需) — 要获取的模型 ID。
响应体
aliases(array<string>, 必需) — 用户可在请求的模型字段中使用的模型别名 ID。created(integer, 必需) — 模型创建时间的 Unix 时间戳。fingerprint(string, 必需) — 托管模型的 xAI 系统配置的指纹。id(string, 必需) — 模型 ID。input_modalities(array<string>, 必需) — 模型支持的输入模态(例如 "text", "image"; 接受参考音频的模型为 "audio")。object(string, 必需) — 对象类型,始终为"model"。output_modalities(array<string>, 必需) — 模型支持的输出模态(例如 "video")。owned_by(string, 必需) — 模型所有者。version(string, 必需) — 模型版本。
响应示例:
{
"id": "grok-imagine-video",
"fingerprint": "fp_898ae9f31c",
"created": 1743724800,
"object": "model",
"owned_by": "xai",
"version": "1.0",
"input_modalities": [
"text",
"image"
],
"output_modalities": [
"video"
],
"aliases": []
}