curl --request POST \
--url https://api.tikway.ai/v1beta/cachedContents \
--header 'Content-Type: application/json' \
--header 'x-goog-api-key: <api-key>' \
--data '
{
"model": "models/gemini-2.5-flash",
"displayName": "unicorn-story-context",
"systemInstruction": {
"parts": [
{
"text": "You are a creative bedtime-story assistant. Keep stories gentle and suitable for children."
}
]
},
"contents": [
{
"role": "user",
"parts": [
{
"text": "Reference material: Unicorns are magical horses with a single horn. They live in enchanted forests and help kind-hearted people."
}
]
}
],
"ttl": "3600s"
}
'import requests
url = "https://api.tikway.ai/v1beta/cachedContents"
payload = {
"model": "models/gemini-2.5-flash",
"displayName": "unicorn-story-context",
"systemInstruction": { "parts": [{ "text": "You are a creative bedtime-story assistant. Keep stories gentle and suitable for children." }] },
"contents": [
{
"role": "user",
"parts": [{ "text": "Reference material: Unicorns are magical horses with a single horn. They live in enchanted forests and help kind-hearted people." }]
}
],
"ttl": "3600s"
}
headers = {
"x-goog-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-goog-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'models/gemini-2.5-flash',
displayName: 'unicorn-story-context',
systemInstruction: {
parts: [
{
text: 'You are a creative bedtime-story assistant. Keep stories gentle and suitable for children.'
}
]
},
contents: [
{
role: 'user',
parts: [
{
text: 'Reference material: Unicorns are magical horses with a single horn. They live in enchanted forests and help kind-hearted people.'
}
]
}
],
ttl: '3600s'
})
};
fetch('https://api.tikway.ai/v1beta/cachedContents', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.tikway.ai/v1beta/cachedContents",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'models/gemini-2.5-flash',
'displayName' => 'unicorn-story-context',
'systemInstruction' => [
'parts' => [
[
'text' => 'You are a creative bedtime-story assistant. Keep stories gentle and suitable for children.'
]
]
],
'contents' => [
[
'role' => 'user',
'parts' => [
[
'text' => 'Reference material: Unicorns are magical horses with a single horn. They live in enchanted forests and help kind-hearted people.'
]
]
]
],
'ttl' => '3600s'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-goog-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.tikway.ai/v1beta/cachedContents"
payload := strings.NewReader("{\n \"model\": \"models/gemini-2.5-flash\",\n \"displayName\": \"unicorn-story-context\",\n \"systemInstruction\": {\n \"parts\": [\n {\n \"text\": \"You are a creative bedtime-story assistant. Keep stories gentle and suitable for children.\"\n }\n ]\n },\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Reference material: Unicorns are magical horses with a single horn. They live in enchanted forests and help kind-hearted people.\"\n }\n ]\n }\n ],\n \"ttl\": \"3600s\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-goog-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.tikway.ai/v1beta/cachedContents")
.header("x-goog-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"models/gemini-2.5-flash\",\n \"displayName\": \"unicorn-story-context\",\n \"systemInstruction\": {\n \"parts\": [\n {\n \"text\": \"You are a creative bedtime-story assistant. Keep stories gentle and suitable for children.\"\n }\n ]\n },\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Reference material: Unicorns are magical horses with a single horn. They live in enchanted forests and help kind-hearted people.\"\n }\n ]\n }\n ],\n \"ttl\": \"3600s\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.tikway.ai/v1beta/cachedContents")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-goog-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"models/gemini-2.5-flash\",\n \"displayName\": \"unicorn-story-context\",\n \"systemInstruction\": {\n \"parts\": [\n {\n \"text\": \"You are a creative bedtime-story assistant. Keep stories gentle and suitable for children.\"\n }\n ]\n },\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Reference material: Unicorns are magical horses with a single horn. They live in enchanted forests and help kind-hearted people.\"\n }\n ]\n }\n ],\n \"ttl\": \"3600s\"\n}"
response = http.request(request)
puts response.read_body{
"name": "cachedContents/abc123xyz",
"displayName": "starry-night-reference",
"model": "models/gemini-2.5-flash",
"createTime": "2026-09-10T08:30:00.123456Z",
"updateTime": "2026-09-10T08:30:00.123456Z",
"expireTime": "2026-09-10T09:30:00.123456Z",
"usageMetadata": {
"totalTokenCount": 1864
}
}Create Cached Content
curl --request POST \
--url https://api.tikway.ai/v1beta/cachedContents \
--header 'Content-Type: application/json' \
--header 'x-goog-api-key: <api-key>' \
--data '
{
"model": "models/gemini-2.5-flash",
"displayName": "unicorn-story-context",
"systemInstruction": {
"parts": [
{
"text": "You are a creative bedtime-story assistant. Keep stories gentle and suitable for children."
}
]
},
"contents": [
{
"role": "user",
"parts": [
{
"text": "Reference material: Unicorns are magical horses with a single horn. They live in enchanted forests and help kind-hearted people."
}
]
}
],
"ttl": "3600s"
}
'import requests
url = "https://api.tikway.ai/v1beta/cachedContents"
payload = {
"model": "models/gemini-2.5-flash",
"displayName": "unicorn-story-context",
"systemInstruction": { "parts": [{ "text": "You are a creative bedtime-story assistant. Keep stories gentle and suitable for children." }] },
"contents": [
{
"role": "user",
"parts": [{ "text": "Reference material: Unicorns are magical horses with a single horn. They live in enchanted forests and help kind-hearted people." }]
}
],
"ttl": "3600s"
}
headers = {
"x-goog-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-goog-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'models/gemini-2.5-flash',
displayName: 'unicorn-story-context',
systemInstruction: {
parts: [
{
text: 'You are a creative bedtime-story assistant. Keep stories gentle and suitable for children.'
}
]
},
contents: [
{
role: 'user',
parts: [
{
text: 'Reference material: Unicorns are magical horses with a single horn. They live in enchanted forests and help kind-hearted people.'
}
]
}
],
ttl: '3600s'
})
};
fetch('https://api.tikway.ai/v1beta/cachedContents', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.tikway.ai/v1beta/cachedContents",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'models/gemini-2.5-flash',
'displayName' => 'unicorn-story-context',
'systemInstruction' => [
'parts' => [
[
'text' => 'You are a creative bedtime-story assistant. Keep stories gentle and suitable for children.'
]
]
],
'contents' => [
[
'role' => 'user',
'parts' => [
[
'text' => 'Reference material: Unicorns are magical horses with a single horn. They live in enchanted forests and help kind-hearted people.'
]
]
]
],
'ttl' => '3600s'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-goog-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.tikway.ai/v1beta/cachedContents"
payload := strings.NewReader("{\n \"model\": \"models/gemini-2.5-flash\",\n \"displayName\": \"unicorn-story-context\",\n \"systemInstruction\": {\n \"parts\": [\n {\n \"text\": \"You are a creative bedtime-story assistant. Keep stories gentle and suitable for children.\"\n }\n ]\n },\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Reference material: Unicorns are magical horses with a single horn. They live in enchanted forests and help kind-hearted people.\"\n }\n ]\n }\n ],\n \"ttl\": \"3600s\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-goog-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.tikway.ai/v1beta/cachedContents")
.header("x-goog-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"models/gemini-2.5-flash\",\n \"displayName\": \"unicorn-story-context\",\n \"systemInstruction\": {\n \"parts\": [\n {\n \"text\": \"You are a creative bedtime-story assistant. Keep stories gentle and suitable for children.\"\n }\n ]\n },\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Reference material: Unicorns are magical horses with a single horn. They live in enchanted forests and help kind-hearted people.\"\n }\n ]\n }\n ],\n \"ttl\": \"3600s\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.tikway.ai/v1beta/cachedContents")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-goog-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"models/gemini-2.5-flash\",\n \"displayName\": \"unicorn-story-context\",\n \"systemInstruction\": {\n \"parts\": [\n {\n \"text\": \"You are a creative bedtime-story assistant. Keep stories gentle and suitable for children.\"\n }\n ]\n },\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Reference material: Unicorns are magical horses with a single horn. They live in enchanted forests and help kind-hearted people.\"\n }\n ]\n }\n ],\n \"ttl\": \"3600s\"\n}"
response = http.request(request)
puts response.read_body{
"name": "cachedContents/abc123xyz",
"displayName": "starry-night-reference",
"model": "models/gemini-2.5-flash",
"createTime": "2026-09-10T08:30:00.123456Z",
"updateTime": "2026-09-10T08:30:00.123456Z",
"expireTime": "2026-09-10T09:30:00.123456Z",
"usageMetadata": {
"totalTokenCount": 1864
}
}授权
Tikway API Key。按 Gemini 原生协议通过 x-goog-api-key 请求头传递。
请求体
创建缓存内容的请求体。缓存内容经过预处理后,可以在后续生成请求中重复使用。缓存只能用于创建它时指定的模型。
用于创建和使用该缓存的模型资源名称。缓存只能用于这里指定的模型,格式为 models/{model}。该字段为必填项,创建后不可修改。
^models/[^/]+$"models/gemini-1.5-flash-001"
"models/gemini-2.5-flash"
需要缓存的内容列表。可以包含单轮内容,也可以按照对话顺序包含多轮历史内容。该字段仅用于输入,缓存创建后不可修改。
1Hide child attributes
Hide child attributes
组成当前内容的部分列表。每个 Part 可表示文本、内联文件、已上传文件、函数调用、函数响应或代码执行信息。
1Hide child attributes
Hide child attributes
纯文本内容。
代码执行环境返回的执行结果。
Hide child attributes
Hide child attributes
表示当前 Part 是否属于模型的思考内容。通常由服务端生成,回传历史内容时应保持原值。
模型思考内容的签名。回传模型历史内容时应保持原样,不应由客户端修改或自行生成。
内容所属角色。user 表示用户内容,model 表示模型生成的历史内容。
user, model 模型在后续生成内容时可以使用的工具列表。该字段仅用于输入,缓存创建后不可修改。
Hide child attributes
Hide child attributes
客户端提供给模型使用的函数声明列表。
1Hide child attributes
Hide child attributes
函数名称。名称应唯一,并符合服务端支持的命名规则。
函数用途和调用场景说明,模型将根据该说明判断是否调用函数。
函数参数的 JSON Schema。通常根节点的 type 为 object,并通过 properties 声明参数。
函数返回值的 JSON Schema,用于描述函数执行结果的结构。
启用模型代码执行能力。当前配置对象通常为空。
缓存失效的绝对时间,使用 RFC 3339 格式。服务端输出时会规范化为 UTC 时间。该字段与 ttl 互斥,最多设置其中一个。
"2026-09-08T12:00:00Z"
"2026-09-08T12:00:00.123Z"
缓存的相对有效时长,以秒为单位,最多支持 9 位小数,并以 s 结尾。该字段仅用于输入,与 expireTime 互斥。
^[0-9]+(?:\.[0-9]{1,9})?s$"300s"
"3600s"
"3.5s"
用户为缓存内容设置的可读名称,最多包含 128 个 Unicode 字符。该字段在缓存创建后不可修改。
128工具调用配置。该配置由所有 tools 共享,仅用于输入,缓存创建后不可修改。
Hide child attributes
Hide child attributes
函数调用行为配置。
Hide child attributes
Hide child attributes
函数调用模式。MODE_UNSPECIFIED 表示未指定且不建议使用;AUTO 表示模型自行决定返回文本或调用函数;ANY 表示模型必须调用函数;NONE 表示禁止函数调用;VALIDATED 表示模型可返回文本或调用经过约束验证的函数。
MODE_UNSPECIFIED, AUTO, ANY, NONE, VALIDATED 允许模型调用的函数名称列表。仅应在 mode 为 ANY 或 VALIDATED 时设置,名称必须与 functionDeclarations 中的函数名称一致。
1允许调用的函数名称。
检索工具使用的上下文配置。
Hide child attributes
Hide child attributes
用户内容使用的语言代码,应使用 BCP 47 语言标签,例如 zh-CN、en-US。
是否在模型响应的 Content 中包含服务端工具调用及其响应。设为 true 后,客户端可以观察服务端工具的调用过程。
响应
创建成功后返回的缓存内容资源。响应主要包含缓存标识、模型、创建时间、更新时间、实际过期时间和令牌用量。
缓存内容的唯一资源名称,由服务端生成,格式为 cachedContents/{id}。
^cachedContents/[^/]+$"cachedContents/abc123def456"
该缓存绑定的模型资源名称。缓存只能用于此模型。
^models/[^/]+$"models/gemini-1.5-flash-001"
缓存实际失效的绝对时间。无论请求中使用 expireTime 还是 ttl,服务端都会在响应中返回该字段。
"2026-09-08T11:00:00Z"
创建缓存时设置的可读名称。未设置时可能不返回该字段。
128缓存资源的创建时间,由服务端生成,采用 RFC 3339 格式并通常规范化为 UTC 时间。
"2026-09-08T10:00:00Z"
缓存资源最后一次更新的时间,由服务端生成,采用 RFC 3339 格式并通常规范化为 UTC 时间。
"2026-09-08T10:00:00Z"