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
}
}Authorizations
Tikway API Key. Passed through the x-goog-api-key request header according to the Gemini native protocol.
Body
Create a request body for cached content. The cached content is preprocessed and can be reused in subsequent build requests. The cache can only be used for the model specified when it was created.
The name of the model resource used to create and use this cache. The cache can only be used for the models specified here, in the format models/{model}. This field is required and cannot be modified after creation.
^models/[^/]+$"models/gemini-1.5-flash-001"
"models/gemini-2.5-flash"
A list of content that needs to be cached. It can contain a single round of content, or it can contain multiple historical rounds of content in dialogue order. This field is for input only and cannot be modified after the cache is created.
1Hide child attributes
Hide child attributes
A list of parts that make up the current content. Each Part can represent text, inline files, uploaded files, function calls, function responses, or code execution information.
1Hide child attributes
Hide child attributes
Plain text content.
To embed binary data directly in the request, the data needs to be Base64 encoded.
Hide child attributes
Hide child attributes
File reference obtained after uploading via Gemini File API.
Hide child attributes
Hide child attributes
Function call information generated by the model in historical conversations.
Hide child attributes
Hide child attributes
The name of the function to be called should be consistent with the function name declared in tools.functionDeclarations.
The parameters used when calling the function, the structure is determined by the parameters JSON Schema of the corresponding function.
The result returned to the model after the client executes the function.
Hide child attributes
Hide child attributes
The name of the executed function should be consistent with the corresponding functionCall.name.
Function execution result. Can contain data, status, or error information returned by the function.
Code generated by the model that can be run by the code execution environment.
Hide child attributes
Hide child attributes
The programming language used by the code. LANGUAGE_UNSPECIFIED means unspecified, PYTHON means Python.
LANGUAGE_UNSPECIFIED, PYTHON The source code needs to be executed.
Executable code block ID.
The execution results returned by the code execution environment.
Hide child attributes
Hide child attributes
Code execution status. OUTCOME_OK indicates success, OUTCOME_FAILED indicates failure, and OUTCOME_DEADLINE_EXCEEDED indicates execution timeout.
OUTCOME_UNSPECIFIED, OUTCOME_OK, OUTCOME_FAILED, OUTCOME_DEADLINE_EXCEEDED Standard output, error messages, or other textual results produced by code execution.
The corresponding code block ID.
Indicates whether the current Part belongs to the thinking content of the model. Usually generated by the server, the original value should be maintained when returning historical content.
A signature of what the model thinks about. The historical content of the model should be kept intact when returned and should not be modified or generated by the client.
Custom metadata associated with the content block.
How video content is processed.
Audio transcription information.
Speech synthesis related metadata.
Server-side tool calls that need to be returned by the client.
The execution result of the server tool call.
Video content metadata.
The role the content belongs to. user represents user content, and model represents historical content generated by the model.
user, model A list of tools that the model can use when subsequently generating content. This field is for input only and cannot be modified after the cache is created.
Hide child attributes
Hide child attributes
A list of function declarations provided by the client for use by the model.
1Hide child attributes
Hide child attributes
function name. The name should be unique and comply with the naming rules supported by the server.
Function usage and calling scenario description, the model will determine whether to call the function based on this description.
JSON Schema of function parameters. Usually the type of the root node is object, and the parameters are declared through properties.
JSON Schema of the function return value, used to describe the structure of the function execution result.
How the function call is executed.
UNSPECIFIED, BLOCKING, NON_BLOCKING JSON Schema of function parameters; mutually exclusive with parameters .
JSON Schema of the function response; mutually exclusive with response .
Enable model code execution capabilities. The current configuration object is usually empty.
Google Search retrieves the configuration.
Google Search tool configuration.
Computer operating tool configuration.
URL context tool configuration.
File search tool configuration.
Connectable MCP server.
Geolocation search tool configuration.
Absolute time of cache expiration, using RFC 3339 format. The server output will be normalized to UTC time. This field is mutually exclusive with ttl, at most one of them can be set.
"2026-09-08T12:00:00Z"
"2026-09-08T12:00:00.123Z"
The relative validity period of the cache, in seconds, supports up to 9 decimal places, and ends with s. This field is for input only and is mutually exclusive with expireTime.
^[0-9]+(?:\.[0-9]{1,9})?s$"300s"
"3600s"
"3.5s"
A human-readable name set by the user for the cached content, containing up to 128 Unicode characters. This field cannot be modified after the cache is created.
128System commands set by the developer. Currently only plain text Parts are supported. This field is for input only and cannot be modified after the cache is created.
Hide child attributes
Hide child attributes
The role of the system command content. This field can usually be omitted.
user, model Tool call configuration. This configuration is shared by all tools and is only used for input. The cache cannot be modified after it is created.
Hide child attributes
Hide child attributes
Function call behavior configuration.
Hide child attributes
Hide child attributes
Function calling pattern. MODE_UNSPECIFIED means unspecified and not recommended; AUTO means the model can return text or call a function at its discretion; ANY means the model must call a function; NONE means function calls are prohibited; VALIDATED means the model can return text or call a constraint-validated function.
MODE_UNSPECIFIED, AUTO, ANY, NONE, VALIDATED A list of function names that the model is allowed to call. Should only be set when mode is ANY or VALIDATED, and the name must match the function name in functionDeclarations.
1Function names that are allowed to be called.
Retrieves the context configuration used by the tool.
Hide child attributes
Hide child attributes
The latitude and longitude of the user's location follows the WGS84 coordinate standard.
The language code used for user content should use BCP 47 language tags, such as zh-CN, en-US.
Whether to include the server tool call and its response in the Content of the model response. After setting to true, the client can observe the calling process of the server tool.
Response
The cached content resource returned after successful creation. The response mainly contains cache identification, model, creation time, update time, actual expiration time and token usage.
The unique resource name of cached content, generated by the server, in the format cachedContents/{id}.
^cachedContents/[^/]+$"cachedContents/abc123def456"
The name of the model resource bound to this cache. Caching can only be used with this model.
^models/[^/]+$"models/gemini-1.5-flash-001"
The absolute time at which the cache actually expires. Regardless of whether expireTime or ttl is used in the request, the server will return this field in the response.
"2026-09-08T11:00:00Z"
The human-readable name set when creating the cache. This field may not be returned when not set.
128The creation time of the cached resource, generated by the server, in RFC 3339 format and usually normalized to UTC time.
"2026-09-08T10:00:00Z"
The time when the cached resource was last updated, generated by the server, in RFC 3339 format and usually normalized to UTC time.
"2026-09-08T10:00:00Z"

