aip
Design and review APIs against Google's API Improvement Proposals (AIPs, google.aip.dev), with every approved general AIP bundled and an api-linter wrapper. Use it whenever someone designs, writes or reviews a .proto file, gRPC service, protobuf message or resource-oriented REST API, including resource names and hierarchy, field naming, standard methods (Get/List/Create/Update/Delete), custom methods, pagination, filtering, field masks, long-running operations, error responses, field_behavior annotations, versioning or backwards compatibility. Also use it when an AIP is mentioned by number ("AIP-158"), when someone asks whether an API follows Google's API design guidelines, or when api-linter findings need fixing, even if the word "AIP" never comes up.
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-19
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- aip
- license
- Apache-2.0 (skill and scripts, see LICENSE); bundled AIP text (c) Google LLC under CC BY 4.0, see NOTICE
- description
- Design and review APIs against Google's API Improvement Proposals (AIPs, google.aip.dev), with every approved general AIP bundled and an api-linter wrapper. Use it whenever someone designs, writes or reviews a .proto file, gRPC service, protobuf message or resource-oriented REST API, including resource names and hierarchy, field naming, standard methods (Get/List/Create/Update/Delete), custom methods, pagination, filtering, field masks, long-running operations, error responses, field_behavior annotations, versioning or backwards compatibility. Also use it when an AIP is mentioned by number ("AIP-158"), when someone asks whether an API follows Google's API design guidelines, or when api-linter findings need fixing, even if the word "AIP" never comes up.
- compatibility
- Linting needs Python 3, git and api-linter (go install github.com/googleapis/api-linter/v2/cmd/api-linter@latest). Everything else works without them.
02 资源文件 77
- 许可证LICENSE11.1 KB
- 其他NOTICE1.2 KB
- 参考文档references/aips/0001-aip-purpose-and-guidelines.md12.2 KB
- 参考文档references/aips/0002-aip-numbering.md2.3 KB
- 参考文档references/aips/0003-aip-versioning.md1.7 KB
- 参考文档references/aips/0008-aip-style-and-guidance.md10.5 KB
- 参考文档references/aips/0009-glossary.md8.4 KB
- 参考文档references/aips/0100-api-design-review-faq.md15.5 KB
- 参考文档references/aips/0111-planes.md2.9 KB
- 参考文档references/aips/0121-resource-oriented-design.md9.4 KB
- 参考文档references/aips/0122-resource-names.md19.0 KB
- 参考文档references/aips/0123-resource-types.md6.3 KB
- 参考文档references/aips/0124-resource-association.md4.4 KB
- 参考文档references/aips/0126-enumerations.md4.9 KB
- 参考文档references/aips/0127-http-and-grpc-transcoding.md6.1 KB
- 参考文档references/aips/0128-declarative-friendly-interfaces.md3.5 KB
- 参考文档references/aips/0129-server-modified-values-and-defaults.md5.9 KB
- 参考文档references/aips/0130-methods.md10.2 KB
- 参考文档references/aips/0131-standard-methods-get.md4.0 KB
- 参考文档references/aips/0132-standard-methods-list.md10.3 KB
- 参考文档references/aips/0133-standard-methods-create.md10.1 KB
- 参考文档references/aips/0134-standard-methods-update.md13.4 KB
- 参考文档references/aips/0135-standard-methods-delete.md10.4 KB
- 参考文档references/aips/0136-custom-methods.md9.5 KB
- 参考文档references/aips/0140-field-names.md9.2 KB
- 参考文档references/aips/0141-quantities.md4.1 KB
- 参考文档references/aips/0142-time-and-duration.md6.2 KB
- 参考文档references/aips/0143-standardized-codes.md5.2 KB
- 参考文档references/aips/0144-repeated-fields.md6.8 KB
- 参考文档references/aips/0145-ranges.md3.9 KB
- 参考文档references/aips/0146-generic-fields.md4.2 KB
- 参考文档references/aips/0147-sensitive-fields.md2.9 KB
- 参考文档references/aips/0148-standard-fields.md7.7 KB
- 参考文档references/aips/0149-unset-field-values.md3.5 KB
- 参考文档references/aips/0151-long-running-operations.md8.9 KB
- 参考文档references/aips/0152-jobs.md5.1 KB
- 参考文档references/aips/0153-import-and-export.md6.4 KB
- 参考文档references/aips/0154-resource-freshness-validation.md5.0 KB
- 参考文档references/aips/0155-request-identification.md4.2 KB
- 参考文档references/aips/0156-singleton-resources.md5.2 KB
- 参考文档references/aips/0157-partial-responses.md5.9 KB
- 参考文档references/aips/0158-pagination.md9.7 KB
- 参考文档references/aips/0159-reading-across-collections.md3.4 KB
- 参考文档references/aips/0160-filtering.md11.7 KB
- 参考文档references/aips/0161-field-masks.md5.8 KB
- 参考文档references/aips/0163-change-validation.md2.0 KB
- 参考文档references/aips/0164-soft-delete.md8.9 KB
- 参考文档references/aips/0165-criteria-based-delete.md5.9 KB
- 参考文档references/aips/0180-backwards-compatibility.md13.9 KB
- 参考文档references/aips/0181-stability-levels.md8.4 KB
- 参考文档references/aips/0184-api-version-identifiers.md4.9 KB
- 参考文档references/aips/0185-api-versioning.md11.8 KB
- 参考文档references/aips/0190-naming-conventions.md6.7 KB
- 参考文档references/aips/0191-file-and-directory-structure.md7.7 KB
- 参考文档references/aips/0192-documentation.md7.4 KB
- 参考文档references/aips/0193-errors.md22.0 KB
- 参考文档references/aips/0194-automatic-retry-configuration.md4.3 KB
- 参考文档references/aips/0200-precedent.md6.5 KB
- 参考文档references/aips/0202-fields.md5.5 KB
- 参考文档references/aips/0203-field-behavior-documentation.md13.9 KB
- 参考文档references/aips/0205-beta-blocking-changes.md2.0 KB
- 参考文档references/aips/0210-unicode.md8.3 KB
- 参考文档references/aips/0211-authorization-checks.md3.8 KB
- 参考文档references/aips/0213-common-components.md12.2 KB
- 参考文档references/aips/0214-resource-expiration.md3.6 KB
- 参考文档references/aips/0215-api-specific-protos.md2.9 KB
- 参考文档references/aips/0216-states.md9.8 KB
- 参考文档references/aips/0217-unreachable-resources.md14.3 KB
- 参考文档references/aips/0231-batch-methods-get.md8.2 KB
- 参考文档references/aips/0233-batch-methods-create.md10.7 KB
- 参考文档references/aips/0234-batch-methods-update.md10.6 KB
- 参考文档references/aips/0235-batch-methods-delete.md14.4 KB
- 参考文档references/aips/0236-policy-preview.md16.0 KB
- 参考文档references/examples/library/v1/book.proto7.4 KB
- 参考文档references/index.md14.2 KB
- 参考文档references/UPSTREAM41 B
- 脚本scripts/lint.py15.1 KB
03 SKILL.md 正文
Google AIPs for API design and review
AIPs are Google's API design standards: one short document per topic, each
with numbered rules written as must, should and may. The approved
general AIPs are bundled in references/aips/, so answers come from the text
instead of memory. That matters because the AIPs change: for example,
IDENTIFIER field behavior on name and the guidance on the proto3
optional keyword (AIP-149) are both recent, and older blog posts and
training data contradict them.
How to find the right AIP
- Start from the index at the end of this file. It lists every bundled AIP by category.
- Open the file
references/aips/NNNN-<slug>.md, where NNNN is the zero-padded number (Globreferences/aips/0158-*if unsure of the slug). Long AIPs start with a contents list; the Guidance section holds the rules and Rationale explains them. references/index.mdhas a one-line summary per AIP for when the title alone doesn't tell you which one applies. Grep acrossreferences/aips/for a field or annotation name (update_mask,operation_info,ErrorInfo).references/examples/library/v1/book.protois a small, lint-clean API (a resource, the five standard methods, a custom state-changing method, pagination, filtering, an update mask, etags) to copy patterns from.
Read the relevant AIPs before answering, even when you think you know the rule, and cite them as "AIP-NNN" so the reader can check. Keep must and should apart: a must is a defect, a should is a strong default that can be broken with a documented reason, and a may is optional. Take the strength from the sentence in the AIP, not from memory and not from the wording of an api-linter message (those sometimes say "should" for a must); the reader will act on the label. When the AIP only recommends something without a normative keyword, say "recommended" instead of inventing a strength.
Designing an API
Work outside-in, because each step constrains the next:
- Resources and hierarchy (AIP-121, 122, 123, 124). Name the nouns,
their parents, and resource name patterns such as
publishers/{publisher}/books/{book}. Collection IDs are plural camelCase. - Resource messages (AIP-122, 123, 148, 203).
nameas the identifier with agoogle.api.resourceannotation; standard fields (create_time,update_time,display_name,uid,etag) where they fit. - Standard methods first (AIP-130 to 135): Get, List, Create, Update, Delete with their exact request and response shapes and HTTP mappings. Reach for a custom method (AIP-136) only when a standard one cannot express the operation.
- Fields (AIP-140 to 149, 203, 216): names, types, units, time, enums,
and a
field_behavioron every field of every message used in a request, the resource message included (theetagfield is the exception). - Cross-cutting patterns as needed: pagination (158), filtering (160), ordering (132), field masks (161), long-running operations (151), request IDs for idempotency (155), etags (154), validate-only (163), soft delete (164), errors (193).
- Package and files (AIP-185, 191): a versioned package such as
library.v1, file layout, language package options. - Lint the result (see Linting) and fix or justify every finding.
Show the proto, not only prose. Put a comment on every element (AIP-192); generated docs and client libraries depend on them. Any complete proto file you hand over should compile and lint clean, imports included, because it will be copied as-is.
Reviewing an API
- Run the linter on the files if it is available. It is fast and precise on mechanical issues, which leaves your attention for design.
- Then review what a linter cannot judge: whether the resources model the
domain, whether a custom method should have been a standard one, whether
names are consistent across the API, whether a change breaks existing
clients (AIP-180), and whether errors, idempotency and long-running work
are handled. Think about the actual clients too: if the user named the
languages or transports, check what the design means for them (int64
is a string in proto JSON, and TypeScript generators differ: protobuf-es
uses
bigint, othersnumberorstring; large responses hit gRPC's default 4 MB message limit; REST clients see lowerCamelCase field names through transcoding). - Report findings in this shape, most important first:
### <short title> (AIP-NNN, must|should)
Where: file.proto:LINE, `Message.field` or `Rpc`
Problem: what is wrong and why it matters to API users.
Fix:
<proto snippet or diff>
Group repeats (missing comments on twelve fields) into one finding. End with a short list of what is already right, so the author knows what to keep.
For an API that isn't Google's, say which findings are Google-specific conventions the team can reasonably skip (see Linting) instead of presenting them as defects.
Changing an API that has shipped
Before renaming, retyping, renumbering, removing or changing the behavior of anything already released, read AIP-180. Most such changes break existing clients at the wire level, in generated code, or in behavior. Additive changes (new fields, methods, enum values) are usually safe. A breaking change belongs in a new major version (AIP-185).
Quick reference
The rules people most often get wrong, with the strength the AIP gives them. Each row is a pointer, not a substitute: open the AIP when the details matter, and read the exceptions it lists before calling something a defect.
| Instead of | Use | Strength | AIP |
|---|---|---|---|
created_at, updated_at, creation_date |
create_time, update_time as google.protobuf.Timestamp (standard fields; _time suffix for timestamps) |
should | 148, 142 |
int32 timeout_seconds for a span of time |
google.protobuf.Duration timeout |
should | 142 |
id or book_id as the resource's identifier |
string name with the full resource name, field_behavior = IDENTIFIER |
must | 122, 203 |
| A List method without pagination "for now" | Pagination from the start; adding it later is breaking | must | 158 |
limit / offset on list requests |
page_size and page_token in the request, next_page_token in the response |
should | 158 |
is_active, is_public |
active, public (booleans omit the is prefix, except to avoid a reserved word) |
should | 140 |
| A singular name on a repeated field | The plural (repeated string tags) |
must | 144 |
| An enum without a zero "unspecified" value | First value <ENUM_NAME>_UNSPECIFIED = 0, unless a real zero value such as UNKNOWN is clearer |
should | 126 |
size, distance holding a number with a unit |
The unit as suffix: size_bytes, distance_meters |
must | 141 |
float price or string currency |
google.type.Money for amounts; a field named currency_code (ISO 4217) for a bare currency |
Money: recommended; currency_code: must |
143, 213 |
| Update taking the whole resource with no mask | Partial update: the resource plus google.protobuf.FieldMask update_mask, HTTP PATCH |
partial update: should; once supported, the update_mask field: must |
134, 161 |
CreateBookResponse and similar wrappers |
Get, Create and Update return the resource itself | must | 131, 133, 134 |
| Delete returning the deleted resource | google.protobuf.Empty; the resource only for soft delete |
should | 135, 164 |
| A client-chosen ID mixed into the resource | string book_id on the Create request, not on the resource |
must | 133 |
| Unannotated fields in request messages | (google.api.field_behavior) on every field of every message used in a request, including the resource in Create and Update, with at least REQUIRED, OPTIONAL or OUTPUT_ONLY; the resource's etag gets none |
must (etag: should not) | 203 |
A status string that clients set |
A nested enum State, field state, output only, changed through custom methods |
should | 216 |
| Custom error payloads or bare status codes | google.rpc.Status with canonical codes and an ErrorInfo in details |
must | 193 |
| An RPC that may take minutes returning its result | google.longrunning.Operation with an operation_info annotation, plus the Operations service |
should use an LRO; once used, the annotation and service: must | 151 |
No version, or v1.2, in the package |
The major version at the end of the package: library.v1, library.v1beta |
must | 185 |
| A custom method for what a standard method covers | The standard method; custom methods (:verb) are the exception |
should | 136 |
Linting
scripts/lint.py wraps api-linter, Google's
implementation of the AIP rules. In Claude Code the script is at
${CLAUDE_SKILL_DIR}/scripts/lint.py (use python3 on macOS and Linux,
python on Windows):
python3 "${CLAUDE_SKILL_DIR}/scripts/lint.py" path/to/protos/ [more files or dirs]
python3 "${CLAUDE_SKILL_DIR}/scripts/lint.py" api/ -I third_party/protos --disable-rule core::0191::java-package
Point it at the files where they are. It works out each file's import root
from its package line (or the nearest buf.yaml), so a single file you just
wrote can be linted in place. Files that import each other by package path,
such as import "library/v1/common.proto", need that directory layout or a
-I to the root that has it. The script fetches the googleapis common protos
(google/api, google/rpc, google/type, google/longrunning) into a cache
when an import needs them, picks up an api-linter.yaml from the current
directory, the import roots or their parents, and prints findings grouped by
AIP with paths relative to the current directory and the bundled AIP to read.
Exit code 0 means clean, 1 means findings, 2 means a setup or compile problem;
the message says what to install or which import is missing.
If api-linter is not installed, tell the user the install command the script prints and carry on with a manual review. Don't install tools without asking.
A clean lint is not a good API. The linter checks shapes and names; it cannot tell whether the resource model fits the domain.
The language package options in AIP-191 (core::0191::java-package,
java-multiple-files, java-outer-classname, and the C#, PHP and Ruby
equivalents) matter for Google's multi-language client libraries. Teams that
only generate Go or TypeScript often disable them. Disable a rule with
--disable-rule, with an api-linter.yaml:
- included_paths: ["**/*.proto"]
disabled_rules: ["core::0191::java-package"]
or with a comment, which keeps the reason next to the code. Put it directly
above the element the rule is about: a message, field or RPC for most rules,
and the syntax or package line for file-level rules such as the AIP-191
options:
// (-- api-linter: core::0191::java-package=disabled
// aip.dev/not-precedent: We do not generate Java clients. --)
package library.v1;
Path patterns in an api-linter.yaml (included_paths, excluded_paths) are
matched against paths relative to each file's import root, such as
library/v1/book.proto, not relative to the config file.
REST and OpenAPI
The AIPs are written against protobuf but describe HTTP APIs too. AIP-127 maps
each RPC to an HTTP verb and URI, and the standard methods give the REST shape:
GET /v1/{name=publishers/*/books/*}, PATCH with an update mask,
POST /v1/{name=publishers/*/books/*}:archive for a custom method. For an
OpenAPI or hand-written REST API, apply the same resource model, naming,
pagination and error rules, and translate proto field names to lowerCamelCase
JSON. api-linter only reads protos.
AIP index
Process and meta AIPs (1 to 9, 100, 200, 205) are bundled as well; they cover how AIPs are written and reviewed rather than how to design an API.
<!-- BEGIN GENERATED INDEX (tools/sync_aips.py) -->
- API Concepts: 111 Planes
- Resource Design: 121 Resource-oriented design, 122 Resource names, 123 Resource types, 124 Resource association, 126 Enumerations, 128 Declarative-friendly interfaces, 129 Server-Modified Values and Defaults, 156 Singleton resources, 236 Policy preview
- Operations: 130 Methods, 131 Standard methods: Get, 132 Standard methods: List, 133 Standard methods: Create, 134 Standard methods: Update, 135 Standard methods: Delete, 136 Custom methods, 151 Long-running operations, 231 Batch methods: Get, 233 Batch methods: Create, 234 Batch methods: Update, 235 Batch methods: Delete
- Fields: 140 Field names, 202 Fields, 203 Field behavior documentation, 141 Quantities, 142 Time and duration, 143 Standardized codes, 144 Repeated fields, 145 Ranges, 146 Generic fields, 147 Sensitive fields, 148 Standard fields, 149 Unset field values, 216 States
- Design Patterns: 152 Jobs, 153 Import and export, 154 Resource freshness validation, 155 Request identification, 157 Partial responses, 158 Pagination, 159 Reading across collections, 160 Filtering, 161 Field masks, 163 Change validation, 164 Soft delete, 165 Criteria-based delete, 210 Unicode, 211 Authorization checks, 214 Resource expiration, 217 Unreachable resources
- Compatibility and Versioning: 180 Backwards compatibility, 181 Stability levels, 184 API version identifiers, 185 API Versioning
- Polish: 190 Naming conventions, 191 File and directory structure, 192 Documentation, 193 Errors, 194 Automatic retry configuration
- Protocol buffers: 127 HTTP and gRPC Transcoding, 213 Common components, 215 API-specific protos
<!-- END GENERATED INDEX -->