Volcengine SDK Code Generator
Generate complete, runnable Volcengine SDK code from natural-language descriptions, and answer SDK configuration questions.
Workflow
When a user describes a Volcengine API operation, follow these steps:
Step 1: Identify Target Service, Operation, and Advanced Configuration Needs
Parse the user's description to determine:
- - Target service: which Volcengine service (e.g., ECS, VPC, TOS, billing)
- Target operation: what operation to perform (e.g., list instances, create a VPC, query billing)
- Target language: which programming language (Go, Python, PHP, Java, Node.js). If not specified, ask the user.
- Advanced configuration needs: whether the user mentions or the scenario implies any of the following:
-
Retry: user mentions "retry", "fault tolerance", or the operation is a write/create type (prone to throttling)
-
Timeout: user mentions "timeout", or the operation involves large data volumes (batch queries, file uploads)
-
Credentials: user mentions "STS", "AssumeRole", "temporary credentials", "OIDC", or explicitly wants to avoid hardcoding AK/SK
-
Proxy/network: user mentions "proxy" or "internal network"
-
Debug mode: user mentions "debug" or "logging"
-
Connection pooling: user mentions "connection pool", "high concurrency", or "pool"
If the user explicitly requests these, include the corresponding configuration in the generated code. If not explicitly requested but implied by the scenario (e.g., resource creation naturally warrants retry), include suggested configuration as comments.
Step 2: Query Service Metadata via Volcengine API Explorer
Use the following APIs to find the correct service code, version, and action name. This step is critical because guessing often produces incorrect code — the API Explorer is the authoritative source.
2a. Find the ServiceCode
Fetch the service catalog:
GET https://api.volcengine.com/api/common/explorer/services
Response structure:
{
"Result": {
"Categories": [
{
"CategoryName": "...",
"Services": [
{
"ServiceCn": "Cloud Server",
"ServiceCode": "ecs",
"Product": "ECS",
"IsSdkAvailable": true,
"RegionType": "regional"
}
]
}
]
}
}
Match the user's intent to the correct
ServiceCode based on
ServiceCn,
Product, and category name.
2b. Find the API version
CODEBLOCK2
Response:
{
"Result": {
"Versions": [
{
"ServiceCode": "billing",
"Version": "2022-01-01",
"IsDefault": 0
}
]
}
}
Use the version with
IsDefault == 1. If no default version exists, use the latest available.
2c. Find the Action name
CODEBLOCK4
Response:
{
"Result": {
"Groups": [
{
"Name": "Instance",
"Apis": [
{
"Action": "DescribeInstances",
"NameCn": "Query instance list",
"Description": "..."
}
]
}
]
}
}
Match user intent using the
Action name and
NameCn (Chinese name).
2c-alt: Search API (when direct lookup fails)
If the service catalog or API list cannot clearly match the user's description — for example, the user uses vague terms, Chinese names that don't map directly to a ServiceCode, or the API list doesn't seem to contain what the user wants — use the search API as a fallback:
CODEBLOCK6
Search terms can be Chinese or English — use whichever best matches the user's description.
Response structure:
CODEBLOCK7
Select the best match based on ServiceCn, Action, and highlight text, then continue to step 2d.
The search API is particularly useful when:
- - The user describes the operation in natural language but doesn't know which service owns it
- A service has too many APIs to browse manually
- The description spans multiple services (search returns results across all services)
2d. Get full API parameter details
CODEBLOCK8
Returns the full Swagger/OpenAPI specification, including:
- - HTTP method (GET/POST)
- All request parameters with types, required flags, and descriptions
- Response structure
- Constraints and validation rules
x-demo field: contains requestDemo and responseDemo with official examples
Read this specification carefully — it is essential for generating accurate code.
2e. Extract parameter example values (from x-demo requestDemo)
The info.x-demo array in the Swagger response contains requestDemo — official request examples. Extract realistic parameter values from these to populate generated code.
Extraction process:
- 1. Locate
info.x-demo[0].requestDemo and parse the request body JSON - Use requestDemo values as example values in generated code — they are more accurate and realistic than invented values
- For masked values (e.g.,
cc5silum********), keep the masked format and add a comment prompting the user to replace with real values - If a parameter value is a JSON string (e.g., a
Config field), format it clearly and comment each sub-field
Example: for VKE CreateAddon, requestDemo contains:
{
"ClusterId": "cc5silum********",
"Name": "ingress-nginx",
"DeployMode": "Unmanaged",
"DeployNodeType": ["VirtualNode"],
"Config": "{\"Replica\":1,\"Resource\":{\"Request\":{\"Cpu\":\"0.25\",\"Memory\":\"512Mi\"},\"Limit\":{\"Cpu\":\"0.5\",\"Memory\":\"1024Mi\"}},\"PrivateNetwork\":{\"SubnetId\":\"subnet-2d61qn69iji****\",\"IpVersion\":\"IPV4\"}}"
}
Use these example values directly instead of empty placeholders.
2f. Retrieve detailed configuration for complex parameters
Some parameter description fields contain documentation links (e.g., https://www.volcengine.com/docs/...) pointing to detailed configuration guides. For complex parameters, fetch these links for more information:
When to consult documentation:
- - The parameter value is a JSON string with a "see detailed configuration" reference in the description (e.g., VKE
Config) - The parameter is a nested structure whose sub-field format is documented externally
- The
enum values have unclear meanings that are explained in the documentation
Processing flow:
- 1. Check whether the parameter
description contains a volcengine.com/docs link - If so, use WebFetch to retrieve the linked page and extract configuration details relevant to the parameter
- Incorporate documentation examples into the generated code as comments or structured parameters
- If the documentation is inaccessible, fall back to requestDemo example values
2g. Determine required and recommended parameters
Required-field detection relies on multiple sources, not just the required array:
- 1. Explicitly required: listed in the Swagger
required array - Implied by description: the description contains phrases like "must specify", "required", or equivalent
- Logically required: semantically essential even if not formally marked (e.g., instance type and network config when creating resources)
- Conditionally required: the description states "required when X=Y" — if the user's scenario matches, include it
Parameter value priority:
- 1. requestDemo example values (highest priority): use the official examples directly
example field: individual parameter example values from the Swagger spec- enum values: pick the most common or general-purpose option
- Documentation recommendations: values extracted from linked docs
- Industry conventions: reasonable defaults following cloud-computing norms (e.g.,
172.16.0.0/16 for CIDR, descriptive names for instances)
Step 3: Consult SDK Configuration References (as needed)
If Step 1 identified advanced configuration needs, read the corresponding reference file for the target language to get accurate configuration code:
| Language | Reference File |
|---|
| Go | INLINECODE27 |
| Python |
references/sdk-integration-python.md |
| Java |
references/sdk-integration-java.md |
| Node.js |
references/sdk-integration-nodejs.md |
| PHP |
references/sdk-integration-php.md |
These files contain verified code snippets for retry, timeout, credentials, proxy, connection pooling, and debug configuration. Use these patterns directly rather than writing from memory — SDK configuration varies significantly across languages, and the reference files ensure accuracy.
Step 4: Generate Complete SDK Code
Generate a complete, runnable code example following these rules:
General Rules (all languages)
- 1. Authentication: read AK/SK from environment variables
VOLCENGINE_ACCESS_KEY and VOLCENGINE_SECRET_KEY by default. If the user needs a different auth method (STS, AssumeRole, OIDC), use the corresponding pattern from the reference files. The exact reading mechanism varies by language — see each language section and the reference files. - Region: default to
cn-beijing for regional services. Add a comment noting that users can change this. - Required parameters: include all required parameters (sources per step 2g), using realistic example values from requestDemo or example fields. Add a comment next to each value explaining its meaning and source.
- Parameter value quality: values must follow realistic formats and business semantics, not simple placeholders:
- Instance IDs: use masked format like
i-abc123****** (from requestDemo)
- CIDRs: use reasonable ranges like
172.16.0.0/16
- Enums: use the most common option
- Nested JSON configs: expand into readable multi-line format with per-field comments
- 5. Complex parameter handling: for parameters whose value is a JSON string (e.g., VKE Config), build a struct/dict first and then serialize to JSON, rather than hardcoding a long string. This makes the code more readable and easier to modify.
- Optional parameters: include commonly-used optional parameters (e.g., pagination) as commented-out lines with explanations.
- Error handling: include standard error handling for the target language.
- Output: print the response in a readable format (e.g., formatted JSON).
- Comments: add a header comment describing the code's purpose. Add inline comments for non-obvious parameters. Match comment language to the user's prompt language.
- Advanced configuration integration: when the user has advanced config needs, weave the configuration naturally into the main code (not as a separate block), producing a single runnable file:
-
Retry: add retry settings during client/config initialization, with comments explaining defaults and tunable parameters
-
Timeout: set global timeout during client initialization; show per-request timeout usage if needed
-
Credentials: replace the default AK/SK auth code with the user-specified method (STS, AssumeRole, etc.)
-
Proxy: add proxy settings in client configuration
-
Debug: enable debug mode in client configuration
-
Connection pooling: set pool parameters in client configuration
Go
The Go SDK uses {Action}Input structs (not Request). Services are instantiated via {service}.New(sess).
CODEBLOCK10
Key points:
- - Package path:
github.com/volcengine/volcengine-go-sdk/service/{service} (lowercase, e.g., billing, ecs, vpc) - Config chain: INLINECODE44
- Session:
session.NewSession(config) (returns session and error) - Service client:
{service}.New(sess) (e.g., billing.New(sess), ecs.New(sess)) - Request struct:
{Action}Input (e.g., ListAvailableInstancesInput, DescribeInstancesInput) - Method:
svc.{Action}(input), PascalCase action name
Python
The Python SDK uses {SERVICE}Api (uppercase service name) and {Action}Request models.
CODEBLOCK11
Key points:
- - Package:
volcenginesdkcore + volcenginesdk{service} (all lowercase, no separators, e.g., volcenginesdkbilling, volcenginesdkecs) - Config:
volcenginesdkcore.Configuration(), set .ak, .sk, .region, then INLINECODE63 - API class:
volcenginesdk{service}.{SERVICE}Api() — service name ALL CAPS (e.g., BILLINGApi, ECSApi, VPCApi) - Request class:
volcenginesdk{service}.{Action}Request(...) (PascalCase, e.g., ListAvailableInstancesRequest) - Method:
api_instance.{action_snake_case}(request) — snake_case (e.g., list_available_instances, describe_instances) - Exception: INLINECODE73
Java
The Java SDK uses {ServiceName}Api and {Action}Request models under com.volcengine.{service}.
CODEBLOCK12
Key points:
- - Package:
com.volcengine.{service} (lowercase, e.g., com.volcengine.billing, com.volcengine.ecs) - ApiClient: INLINECODE80
- API class:
{ServiceName}Api (PascalCase, e.g., BillingApi, EcsApi) — constructor takes INLINECODE84 - Request class:
{Action}Request (e.g., ListAvailableInstancesRequest) — set params via setters - Method:
api.{actionCamelCase}(request) — camelCase (e.g., listAvailableInstances, describeInstances) - Exception:
ApiException, use e.getResponseBody() for details
Node.js
The Node.js SDK uses a command pattern: {SERVICE}Client + {Action}Command.
CODEBLOCK13
Key points:
- - Package:
@volcengine/{service} (lowercase, e.g., @volcengine/ecs, @volcengine/vpc) - Client:
{SERVICE}Client (ALL CAPS service name, e.g., ECSClient, VPCClient) - Command:
{Action}Command (PascalCase, e.g., DescribeInstancesCommand, CreateVpcCommand) - Invocation:
client.send(command) — async, returns a Promise - Auth: automatically reads
VOLCENGINE_ACCESS_KEY and VOLCENGINE_SECRET_KEY from env; can also pass accessKeyId/secretAccessKey in the client constructor
PHP
The PHP SDK uses classes under the \Volcengine\{Service}\ namespace.
CODEBLOCK14
Key points:
- - Config: INLINECODE109
- API class:
\Volcengine\{Service}\Api\{SERVICE}Api — namespace uses PascalCase Service (e.g., Billing), class name uses ALL CAPS (e.g., BILLINGApi) - Constructor: takes
GuzzleHttp\Client() and INLINECODE115 - Request class:
\Volcengine\{Service}\Model\{Action}Request (e.g., \Volcengine\Billing\Model\ListAvailableInstancesRequest) - Set params via setters: INLINECODE118
- Method:
$apiInstance->{actionCamelCase}($request) (e.g., listAvailableInstances)
Step 5: Present Results
After generating code:
- 1. Display the complete code in a code block with the correct language tag
- List the dependencies the user needs to install (
go get, pip install, npm install, composer require, Maven/Gradle coordinates) - Remind the user to set environment variables:
export VOLCENGINE_ACCESS_KEY="your-access-key"
export VOLCENGINE_SECRET_KEY="your-secret-key"
- 4. Note important constraints from the API spec (rate limits, required permissions, data range limits, etc.)
- If the code includes advanced configuration, briefly explain each setting's purpose, defaults, and tuning advice. For example:
- "Retry defaults to 3 attempts, covers network errors and throttling — adjust via
WithMaxRetries"
- "Connection timeout defaults to 30s; consider increasing for large batch queries"
Answering SDK Configuration Questions
When the user asks how to configure or use the Volcengine SDK (rather than generate API call code), follow this approach:
Step 1: Identify the User's Need
Common configuration topics:
- - Authentication: AK/SK, STS Token, AssumeRole, OIDC, SAML
- Retry: enable/disable, max attempts, backoff strategy, custom retry conditions
- Timeout: connection timeout, read timeout, per-request timeout
- Proxy: HTTP/HTTPS proxy configuration
- Endpoint: custom endpoint, region-based resolution, dual-stack (IPv6)
- SSL/HTTPS: disable SSL verification, TLS version, HTTP vs. HTTPS
- Connection pooling: pool size, keep-alive, idle connections
- Debug: debug mode, logging, middleware
- Error handling: exception types, retryable vs. non-retryable errors
- Environment variables: supported env vars per SDK
Step 2: Consult the Reference Documentation
Read the reference file for the user's target language:
| Language | Reference File |
|---|
| Go | INLINECODE126 |
| Python |
references/sdk-integration-python.md |
| Java |
references/sdk-integration-java.md |
| Node.js |
references/sdk-integration-nodejs.md |
| PHP |
references/sdk-integration-php.md |
These files contain concise code examples for each major configuration topic. Read the relevant file and answer with accurate, copy-paste-ready code.
If the user's question is not covered in the reference file or requires more detail, fetch the full upstream documentation from GitHub:
| Language | Upstream Documentation URL |
|---|
| Go | INLINECODE131 |
| Python |
https://raw.githubusercontent.com/volcengine/volcengine-python-sdk/master/SDK_Integration.md |
| Java |
https://raw.githubusercontent.com/volcengine/volcengine-java-sdk/master/SDK_Integration.md |
| Node.js |
https://raw.githubusercontent.com/volcengine/volcengine-nodejs-sdk/master/SDK_Integration.md |
| PHP |
https://raw.githubusercontent.com/volcengine/volcengine-php-sdk/main/SDK_Integration.md |
Step 3: Provide a Clear Answer
- - Show complete, runnable code snippets demonstrating the configuration
- Explain each setting's purpose and default value
- Mention caveats (e.g., "disabling SSL verification is only appropriate in test environments")
- If the user has not specified a language, ask which one they are using
- Match the answer language to the user's prompt language
Important Notes
- - Always fetch data from the API Explorer — Volcengine APIs are updated frequently, so the Explorer is the authoritative source. Do not rely on memory.
- If the user's description is ambiguous (could map to multiple services or operations), list the options and ask for confirmation.
- If a service has
IsSdkAvailable: false, inform the user that the official SDK may not yet support this service, and provide a raw HTTP request example as an alternative. - For regional services, remind the user to change the region setting if their resources are not in
cn-beijing.
Volcengine SDK 代码生成器
根据自然语言描述生成完整、可运行的 Volcengine SDK 代码,并回答 SDK 配置相关问题。
工作流程
当用户描述一个 Volcengine API 操作时,请遵循以下步骤:
步骤 1:识别目标服务、操作和高级配置需求
解析用户的描述以确定:
- - 目标服务:哪个 Volcengine 服务(例如 ECS、VPC、TOS、billing)
- 目标操作:要执行什么操作(例如列出实例、创建 VPC、查询账单)
- 目标语言:哪种编程语言(Go、Python、PHP、Java、Node.js)。如果未指定,询问用户。
- 高级配置需求:用户是否提及或场景是否暗示以下任何一项:
-
重试:用户提到重试、容错,或操作是写入/创建类型(容易受到限流)
-
超时:用户提到超时,或操作涉及大量数据(批量查询、文件上传)
-
凭证:用户提到STS、AssumeRole、临时凭证、OIDC,或明确希望避免硬编码 AK/SK
-
代理/网络:用户提到代理或内网
-
调试模式:用户提到调试或日志
-
连接池:用户提到连接池、高并发或池
如果用户明确请求这些,在生成的代码中包含相应的配置。如果未明确请求但场景暗示需要(例如,创建资源自然需要重试),将建议的配置作为注释包含。
步骤 2:通过 Volcengine API Explorer 查询服务元数据
使用以下 API 查找正确的服务代码、版本和操作名称。这一步至关重要,因为猜测通常会产生错误的代码——API Explorer 是权威来源。
2a. 查找 ServiceCode
获取服务目录:
GET https://api.volcengine.com/api/common/explorer/services
响应结构:
json
{
Result: {
Categories: [
{
CategoryName: ...,
Services: [
{
ServiceCn: 云服务器,
ServiceCode: ecs,
Product: ECS,
IsSdkAvailable: true,
RegionType: regional
}
]
}
]
}
}
根据 ServiceCn、Product 和分类名称将用户意图匹配到正确的 ServiceCode。
2b. 查找 API 版本
GET https://api.volcengine.com/api/common/explorer/versions?ServiceCode={ServiceCode}
响应:
json
{
Result: {
Versions: [
{
ServiceCode: billing,
Version: 2022-01-01,
IsDefault: 0
}
]
}
}
使用 IsDefault == 1 的版本。如果没有默认版本,使用最新的可用版本。
2c. 查找 Action 名称
GET https://api.volcengine.com/api/common/explorer/apis?ServiceCode={ServiceCode}&Version={Version}&APIVersion={Version}
响应:
json
{
Result: {
Groups: [
{
Name: 实例,
Apis: [
{
Action: DescribeInstances,
NameCn: 查询实例列表,
Description: ...
}
]
}
]
}
}
使用 Action 名称和 NameCn(中文名称)匹配用户意图。
2c-alt:搜索 API(当直接查找失败时)
如果服务目录或 API 列表无法清晰匹配用户的描述——例如,用户使用模糊的术语、中文名称无法直接映射到 ServiceCode,或 API 列表似乎不包含用户想要的内容——使用搜索 API 作为备选方案:
GET https://api.volcengine.com/api/common/search/all?Query={URL编码的搜索词}&Channel=api&Limit=10
搜索词可以是中文或英文——使用最能匹配用户描述的语言。
响应结构:
json
{
Result: {
List: [
{
BizInfo: {
Action: ListProjects,
ServiceCn: 访问控制,
ServiceCode: iam,
Version: 2021-08-01
},
Highlight: [
{Field: title, Summary: 获取项目列表}
]
}
],
Total: 200
}
}
根据 ServiceCn、Action 和高亮文本选择最佳匹配,然后继续步骤 2d。
搜索 API 在以下情况下特别有用:
- - 用户用自然语言描述操作但不知道属于哪个服务
- 一个服务有太多 API 无法手动浏览
- 描述跨多个服务(搜索返回所有服务的结果)
2d. 获取完整的 API 参数详情
GET https://api.volcengine.com/api/common/explorer/api-swagger?ServiceCode={ServiceCode}&Version={Version}&APIVersion={Version}&ActionName={Action}
返回完整的 Swagger/OpenAPI 规范,包括:
- - HTTP 方法(GET/POST)
- 所有请求参数及其类型、必需标志和描述
- 响应结构
- 约束和验证规则
- x-demo 字段:包含带有官方示例的 requestDemo 和 responseDemo
仔细阅读此规范——它对于生成准确的代码至关重要。
2e. 提取参数示例值(来自 x-demo requestDemo)
Swagger 响应中的 info.x-demo 数组包含 requestDemo——官方请求示例。从中提取实际的参数值以填充生成的代码。
提取过程:
- 1. 定位 info.x-demo[0].requestDemo 并解析请求体 JSON
- 使用 requestDemo 值作为生成代码中的示例值——它们比编造的值更准确和实际
- 对于掩码值(例如 cc5silum),保留掩码格式并添加注释提示用户替换为真实值
- 如果参数值是 JSON 字符串(例如 Config 字段),清晰格式化并注释每个子字段
例如:对于 VKE CreateAddon,requestDemo 包含:
json
{
ClusterId: cc5silum,
Name: ingress-nginx,
DeployMode: Unmanaged,
DeployNodeType: [VirtualNode],
Config: {\Replica\:1,\Resource\:{\Request\:{\Cpu\:\0.25\,\Memory\:\512Mi\},\Limit\:{\Cpu\:\0.5\,\Memory\:\1024Mi\}},\PrivateNetwork\:{\SubnetId\:\subnet-2d61qn69iji\,\IpVersion\:\IPV4\}}
}
直接使用这些示例值,而不是空的占位符。
2f. 检索复杂参数的详细配置
某些参数的 description 字段包含文档链接(例如 https://www.volcengine.com/docs/...),指向详细的配置指南。对于复杂参数,获取这些链接以获取更多信息:
何时查阅文档:
- - 参数值是 JSON 字符串,描述中包含查看详细配置的引用(例如 VKE Config)
- 参数是嵌套结构,其子字段格式在外部文档中定义
- enum 值的含义不明确,在文档中有解释
处理流程:
- 1. 检查参数 description 是否包含 volcengine.com/docs 链接
- 如果是,使用 WebFetch 检索链接页面并提取与参数相关的配置详情
- 将文档示例作为注释或结构化参数合并到生成的代码中
- 如果文档无法访问,回退到 requestDemo 示例值
2g. 确定必需和推荐参数
必需字段检测依赖于多个来源,而不仅仅是 required 数组:
- 1. 明确必需:列在 Swagger required 数组中
- 描述暗示:描述包含必须指定、必需或等效短语
- 逻辑必需:即使未正式标记,语义上也是必需的(例如创建资源时的实例类型和网络配置)
- 条件必需:描述说明当 X=Y 时必需——如果用户的场景匹配,则包含它
参数值优先级:
- 1. requestDemo 示例值(最高优先级):直接使用官方示例
- example 字段:Swagger 规范中的单个参数 example 值
- enum 值:选择最常见或通用的选项
- 文档推荐:从链接文档中提取的值
- 行业惯例:遵循云计算规范的合理默认值(例如 CIDR 的 172.16.0.0/16,实例的描述性名称)
步骤 3:查阅 SDK 配置参考(根据需要)
如果步骤 1 确定了高级配置需求,读取目标语言对应的参考文件以获取准确的