Introducing a new way to review your PRs.

Read the announcement

generaltranslation / gt

Full-stack localization for every framework

View on GitHub

22 documents · Updated Nov 23, 2026

docs / translation-api-client

Translation API client and service bindings

The Translation API client is the shared boundary between repository workflows and the General Translation service. It turns the OpenAPI contract into typed service calls and adds common rules for authentication, API versioning, request resilience, pagination, job waiting, batching, error handling, file content handling, and file metadata updates.

System boundary

Public API contract

The General Translation API accepts project and organization requests for file translation, runtime translation, project setup, file delivery, project management, context management, and project asset delivery. It also exposes integration operations for the Google Drive Workspace plugin and design-tool plugins such as Figma and After Effects. The service uses https://api.gtx.dev. Project and organization operations use bearer credentials. Design-tool plugin operations can use an OAuth 2.1 user access token, while Workspace plugin calls use a Google identity token. Organization keys also need a project header for project-scoped work. packages/…/openapi.json packages/…/openapi.json

The OpenAPI document defines the request shapes, response shapes, supported file formats, job states, and error responses that callers can rely on. The current contract lists 2025-01-01.v0, 2025-11-03.v1, 2026-02-18.v1, and 2026-03-06.v1 as API versions. It supports runtime translation of strings, structured content, Markdown, and MDX. It also includes SubRip subtitle files as SRT and .NET resource files as RESX. The client package keeps these rules in one place so command-line, editor, runtime, integration, and other translation workflows use one service boundary. packages/…/openapi.json packages/…/types.gen.ts packages/…/openapi.json

The contract also defines organization API key creation as a user-token-only operation. The request grants organization and project permissions, and the response returns the new key secret for secure storage. packages/…/openapi.json packages/…/types.gen.ts

References: packages/…/openapi.json• L3-18 packages/…/openapi.json• L49-68 packages/…/openapi.json• L80-112 packages/…/openapi.json• L16036-16101 packages/…/openapi.json• L9806-9867 packages/…/types.gen.ts• L14-49 packages/…/types.gen.ts• L210-227

Generated service bindings

The generated bindings map each contract operation to a typed function and map each operation to typed input, success, and error results. The current binding set covers translation work, source and translated file updates, file lifecycle, project and organization access, organization API key creation, context management, branches and tags, plugin integrations, Workspace operations, and CLI wizard sessions. Each operation uses an explicit client, so the workflow that owns the call also owns its base URL, credentials, project scope, API version, and transport rules. The package's codegen command regenerates these bindings from the OpenAPI document. packages/…/sdk.gen.ts packages/…/sdk.gen.ts packages/…/sdk.gen.ts packages/…/sdk.gen.ts packages/…/package.json

The generated types preserve contract variants that callers must understand. Enqueue results can differ by requested API version. Runtime translation reports success or failure for each request key. A multi-file download can return files that are ready and files that are still pending. Workspace and design-tool integrations return product-specific status and result shapes. File updates return the affected records in request order and are safe to repeat. Organization key creation uses a separate permission set and user-token security rule. The convenience wrappers add shared workflow behavior above these generated results without replacing the service contract. packages/…/types.gen.ts packages/…/types.gen.ts packages/…/types.gen.ts packages/…/types.gen.ts packages/…/types.gen.ts packages/…/types.gen.ts

The API refresh adds a common ErrorResponse shape and explicit 415 content-type errors across generated operations. It also records clearer permission and service-state messages, keeps the Workspace plugin operations distinct, exposes organization API key creation, and adds an atomic updateFiles operation for source or translated file metadata. It removes the old file-format T.S contract variant. Changes to the contract and generated bindings must move together because callers compile against these types and operation names. packages/…/openapi.json packages/…/openapi.json packages/…/openapi.json packages/…/openapi.json packages/…/types.gen.ts packages/…/types.gen.ts

References: packages/…/sdk.gen.ts• L190-205 packages/…/sdk.gen.ts• L212-430 packages/…/sdk.gen.ts• L438-457 packages/…/sdk.gen.ts• L1612-1632 packages/…/types.gen.ts• L7-9 packages/…/types.gen.ts• L26-49 packages/…/types.gen.ts• L89-102 packages/…/types.gen.ts• L1617-1754 packages/…/types.gen.ts• L1793-1825 packages/…/types.gen.ts• L210-227 packages/…/types.gen.ts• L2301-2328 packages/…/types.gen.ts• L2699-2753 packages/…/openapi.json• L625-668 packages/…/openapi.json• L5125-5210 packages/…/openapi.json• L16612-16666 packages/…/package.json• L26-36

Request lifecycle

Configured client

createApiClient creates the client that workflows pass to generated service functions. A caller supplies the service URL and can add an API key, project ID, API version, fetch implementation, retry policy, user token provider, and request timeout. The default API version is the newest version listed in the bundled OpenAPI contract. A custom fetch can take ownership of timeouts by setting timeoutMs to false. packages/…/client.ts packages/…/wrappers.test.ts packages/…/wrappers.test.ts

The client adds the selected API version to every request. It adds bearer authentication when an API key exists and adds the project header when a project ID exists. When a workflow uses a user token provider instead of an API key, the client obtains a bearer token for the request and refreshes it once after a 401 response. An explicit per-request Authorization header takes precedence, so the provider does not replace or refresh that credential. A project-scoped key normally identifies the project itself, while an organization key relies on the project header for project-level calls. packages/…/client.ts packages/…/wrappers.test.ts packages/…/openapi.json

The request path is therefore shared by all service operations:

flowchart LR
    A[Workflow input] --> B[Configured API client]
    B --> C[API version and auth context]
    C --> D[Timeout and retry transport]
    D --> E[Generated service operation]
    E --> F[Typed service result]

References: packages/…/client.ts• L8-86 packages/…/client.gen.ts• L27-101 packages/…/wrappers.test.ts• L270-501 packages/…/openapi.json• L41-68

Transport policy

The transport gives each attempt a timeout and then applies a retry policy around the request. The default attempt timeout is 60 seconds. A caller can disable this wrapper when a custom fetch implementation owns timeouts. The default retry mode is exponential backoff with up to three retries. Callers can select linear backoff or disable retries. packages/…/transport.ts packages/…/transport.ts packages/…/client.ts packages/…/wrappers.test.ts

The timeout wrapper forwards cancellation to the fetch request and its request options. A timeout uses a clear timeout error, while a custom fetch error remains unchanged. This gives native and custom fetch implementations the same cancellation boundary. packages/…/transport.ts packages/…/wrappers.test.ts

The transport treats rate limits differently from other temporary errors. A 429 response uses the service's retry timing when present and may be retried for any HTTP method. Server errors and network errors are retried only for idempotent methods. Caller abort stops the retry wait; a response already received is returned, while a fetch failure keeps the abort reason. This limits duplicate side effects while still allowing safe reads and repeatable writes to recover. packages/…/transport.ts packages/…/transport.ts packages/…/wrappers.test.ts

References: packages/…/transport.ts• L1-7 packages/…/transport.ts• L19-50 packages/…/transport.ts• L56-89 packages/…/transport.ts• L91-129 packages/…/client.ts• L62-69 packages/…/wrappers.test.ts• L16-324

Response and error boundary

Generated calls parse successful responses into the types from the OpenAPI contract. A non-throwing call keeps the decoded service error in its error result. A throwOnError call made through createApiClient raises an ApiError with the HTTP status in code when a response exists. The error message comes from the service's error field or plain-text body, with the HTTP status text or status code as a fallback. Fetch failures such as timeout, abort, or network errors remain their original errors. packages/…/client.ts packages/…/errors.ts packages/…/wrappers.test.ts packages/…/openapi.json

This split lets a workflow inspect a typed failure at a local boundary or use exception control flow for a failed operation. The generated contract now gives common HTTP failures a stable error body while keeping endpoint-specific status codes, such as billing failure or missing uploaded files, available to callers. packages/…/types.gen.ts

References: packages/…/client.ts• L79-86 packages/…/errors.ts• L1-27 packages/…/types.gen.ts• L2648-2694 packages/…/wrappers.test.ts• L504-642 packages/…/openapi.json• L70-79

Cursor pagination

paginate turns a generated list operation into an async sequence of items. It starts at an optional cursor, passes through other query options such as the page limit, and follows each response's opaque nextCursor until the service returns null. It loads the next page only when iteration reaches it, so a caller can stop early without fetching unused pages. packages/…/paginate.ts packages/…/types.gen.ts

The helper accepts operations with the page shape of items and nextCursor, and TypeScript infers the yielded item type. A failed page uses the configured client's throwing path. The contract says that pages are read independently, so records can be repeated or missed when the underlying collection changes during traversal. packages/…/paginate.ts packages/…/types.gen.ts

References: packages/…/paginate.ts• L3-31 packages/…/types.gen.ts• L3423-3439 packages/…/paginate.test-d.ts• L13-27 packages/…/wrappers.test.ts• L809-891

Asynchronous work coordination

Job waiting

awaitJobs turns the service's queued-job model into one bounded wait. It asks the jobs endpoint for the still-pending IDs, removes jobs in terminal states, and returns both the final job records and a complete flag. The separately exported pollJobs helper applies the same loop to an injected status loader, so a caller can keep status loading and status normalization at its own boundary. An empty job list completes immediately. packages/…/awaitJobs.ts packages/…/types.gen.ts

The default poll interval is five seconds and the overall wait limit is ten minutes. Completed, failed, and unknown states end the wait for a job. A job that is absent from a status response becomes unknown. If the deadline expires while work remains, complete is false, so callers must not treat the returned list as proof that all work finished. A caller can observe each successful poll through onPoll. packages/…/awaitJobs.ts packages/…/awaitJobs.ts

The polling path also gives each status request its own shorter timeout. This prevents one stalled connection from consuming the whole wait period and keeps caller cancellation separate from the polling deadline. A status request error is rethrown unless the overall deadline has already expired. packages/…/awaitJobs.ts packages/…/transport.ts

The job flow is:

sequenceDiagram
    participant W as Workflow
    participant A as awaitJobs
    participant S as Translation service
    W->>A: Submit job IDs
    loop Until terminal state or deadline
        A->>S: Read pending job statuses
        S-->>A: queued, processing, completed, failed, or unknown
        A->>A: Keep pending IDs and record final states
    end
    A-->>W: complete flag and job results

References: packages/…/awaitJobs.ts• L7-24 packages/…/awaitJobs.ts• L27-45 packages/…/awaitJobs.ts• L50-113 packages/…/types.gen.ts• L1793-1825

Request batching

processBatches turns a large item list into request-sized groups and combines the results into one ordered list. It uses groups of 100 by default, which matches the service limit on source upload, translation enqueue, and multi-file download operations. packages/…/batch.ts packages/…/openapi.json packages/…/openapi.json

Groups run in parallel by default to reduce total wait time. A caller can choose sequential processing when the service or workflow needs lower concurrency. The helper does not decide how to translate an item. It only provides common grouping and result-combine behavior around a batch processor. packages/…/batch.ts

References: packages/…/batch.ts• L1-30 packages/…/openapi.json• L7746-7751 packages/…/openapi.json• L8076-8081 packages/…/types.gen.ts• L2301-2328 packages/…/types.gen.ts• L2576-2596

Content boundary

File payload encoding

The API represents file content as strings. Workflows may hold ordinary UTF-8 text or content that must cross a JSON request boundary in encoded form. The shared file-content helpers provide one conversion rule that works in Node and browser runtimes. They encode text formats and pass binary formats through unchanged. packages/…/base64.ts

encodeFileContent and decodeFileContent apply base64 conversion to every supported file format except binary formats such as LOTTIE, which pass through unchanged. The RESX format is also a supported service format and is uploaded as text. This rule must be applied symmetrically on upload and download so a translated payload is decoded exactly once before a workflow writes or displays it. packages/…/base64.ts packages/…/types.gen.ts packages/…/types.gen.ts packages/…/types.gen.ts

The contract includes catalog and platform resource formats such as XCSTRINGS, DOT_STRINGS, DOT_STRINGSDICT, ANDROID_STRINGS, SRT, and RESX. These formats use the same content boundary even though their higher-level file handling belongs to the calling workflow. packages/…/types.gen.ts

References: packages/…/base64.ts• L1-45 packages/…/types.gen.ts• L26-49 packages/…/types.gen.ts• L2576-2596 packages/…/types.gen.ts• L2755-2799

This page describes the service boundary used by the larger translation system. Read Translation operations for the system-level lifecycle, Locadex operations for dashboard-led project automation, Sanity CMS integration for document translation and editor visibility, and Payload CMS integration for Payload document workflows.

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep spec/openapi.json, the generated request and response types, and the generated operation functions in sync. The package's codegen command and pull request checks depend on this relationship.
  • Keep the published OpenAPI spec export and generated package entry points aligned. Consumers may load the contract from @generaltranslation/…/openapi.json while importing the client from the package root.
  • Keep the default API version in createApiClient aligned with the versions accepted by the OpenAPI contract. The client must continue to select the newest bundled version without relying on an unstable enum order.
  • Keep generated response variants aligned with API-version behavior. In particular, enqueue results, runtime per-item results, pending download entries, Workspace plugin results, and file update results must remain understandable to their callers.
  • Keep updateFiles aligned with its atomic 1–100 item contract. Preserve the rules for omitted fields, nullable metadata, request-order results, and repeat-safe updates.
  • Keep organization API key creation aligned with its user-token-only security rule and the OrgApiKeyPermission enum. API keys cannot create organization API keys.
  • Keep the declared authentication schemes aligned with the client inputs. Changes to API keys, user tokens, Google identity tokens, or plugin credentials must not leave generated security metadata ahead of the configured client.
  • Keep organization-key project scoping aligned with all project-level workflows. Missing or misplaced project context can look like an auth failure even when the key is valid.
  • Keep user-token refresh behavior aligned with explicit per-request authorization. A caller-supplied Authorization header must not be replaced or refreshed by the user-token provider.
  • Keep user-token refresh behavior aligned with the request body and retry path. A refreshed token must not cause a non-repeatable request to run twice without an explicit safety decision.
  • Keep retry behavior aligned with operation side effects. Changes to idempotency rules can change whether a transient error causes a repeated write. Rate-limit retries remain a separate rule because the service can ask any method to wait.
  • Keep timeout cancellation aligned with both native and custom fetch behavior. A timeout must reach the request and fetch call without replacing a custom fetch error or a caller abort reason.
  • Keep the job status union and pollJobs terminal-state rules aligned. A new service state must not remain pending forever or be treated as complete too early.
  • Keep the batch size aligned with service request limits. Endpoint limits and DEFAULT_BATCH_SIZE must change together.
  • Keep list response fields named items and nextCursor when adding operations to paginate. A different page shape needs a separate wrapper contract.
  • Keep cursor forwarding and early iteration behavior aligned with the service's page consistency rules. A change can affect resume points and the number of service calls.
  • Keep ApiError status and message behavior aligned with generated error responses and all callers that use throwOnError.
  • Keep file-format encoding rules aligned between upload and download paths. Adding a format or changing binary-format handling can corrupt content without changing the TypeScript call shape.
  • Keep the public package exports aligned with helper ownership. Callers must use the shared core base64 helper rather than importing a removed API-package export.

Important failure modes

TriggerConsequenceGuard
An organization API key is used without the target project contextProject-scoped calls are rejected even though the key is validSet the project ID when constructing the client for organization-scoped access
An API key is used to create an organization API keyThe service rejects the request because the operation accepts a user token onlyUse the signed-in user-token path for organization key creation
An organization key request grants a permission the caller cannot delegateNo organization key is createdSelect only permissions held by the calling user and allowed by the endpoint
A Workspace plugin call uses a project or user bearer credential instead of a Google identity tokenThe integration request is rejected at the service boundaryUse the credential type declared for the Workspace plugin operation
A request supplies its own Authorization header while a user token provider is configuredThe provider is not called and a 401 is not refreshedTreat the per-request credential as authoritative or omit it to use the provider
A user token provider cannot refresh after a 401The original unauthorized response is returnedReturn a usable refreshed token and use a provider only for user-token requests
A non-idempotent request receives a server error or network errorThe transport returns the failure without automatic replayRetry only at a higher level when the operation is safe to repeat
A request exceeds its per-attempt timeoutThe attempt is aborted with a timeout error; retry policy may start another attemptSet a suitable timeout and use caller cancellation for a wider operation deadline
A caller aborts while a retryable response is waitingThe transport returns the received response instead of sleeping through the abortCheck the response or error at the operation boundary before continuing work
A custom fetch owns timeouts but the client timeout wrapper remains enabledThe client can abort a request before the custom fetch expectsSet timeoutMs: false when the custom fetch owns request timeouts
The job deadline expires with pending IDsawaitJobs returns complete: false, so downstream code may have partial statusCheck complete before downloading or publishing results
A requested job is missing from a status responseThe job is recorded as unknown and no longer polledTreat unknown as an unresolved service result and inspect the returned job records
A request batch exceeds an endpoint's limitThe service rejects the whole batchKeep caller batch sizes at or below the service limit, normally 100
A list changes while pages are being readRecords can be repeated or missed across pagesTreat cursors as traversal state, not as a stable snapshot
A page request fails during paginateIteration stops with an ApiError when the configured client is usedHandle the error around the async iteration and persist a cursor only after consumed work
A file update targets an integration-managed source versionThe service rejects the update and preserves the existing metadataDo not update metadata owned by an external integration
A file update names a missing source file or translationNothing is written for the invalid requestCarry the correct project, branch, file, version, and optional locale identity
A caller uses an upload result without its required branch IDA later file or translation request can target the wrong branch or lack required contextCarry the returned branchId with the file and version IDs
A caller encodes a binary format or skips encoding for a text formatThe service receives content in the wrong representationUse the shared file-content helpers for both upload and download
A caller assumes every enqueue response is the same shapeA legacy or current API version is read with the wrong fieldsSelect the response variant from the requested API version
A runtime translation caller treats one failed request key as a failed whole requestSuccessful keys are discarded or failed keys are shown as translationsInspect each key's success value and its result shape

Key files

FileWhy to read it
packages/…/openapi.jsonDefines the public service contract, server URL, authentication schemes, operations, formats, pagination, response states, file metadata updates, and organization key creation.
packages/…/sdk.gen.tsShows the typed service operations exposed from the OpenAPI contract, including translation, file, file metadata, project, context, organization key, and integration operations.
packages/…/types.gen.tsShows shared service types such as file formats, API versions, page results, job states, response variants, upload identities, runtime results, pending downloads, permissions, file update results, and error results.
packages/…/client.gen.tsShows the common request and response boundary used by generated operations.
packages/…/client.tsDefines client construction, API version selection, authentication headers, per-request authorization precedence, user-token refresh, project scope, timeout choice, and error conversion.
packages/…/errors.tsDefines the public HTTP error shape used by throwing client calls.
packages/…/transport.tsDefines timeout, retry, rate-limit, backoff, and cancellation behavior.
packages/…/paginate.tsDefines cursor traversal and lazy page loading for generated list operations.
packages/…/awaitJobs.tsDefines the bounded polling contract used for asynchronous translation work.
packages/…/batch.tsDefines request grouping and parallel or sequential batch processing.
packages/…/base64.tsShows the shared file payload conversion rule for text and binary formats.
packages/…/paginate.test-d.tsDemonstrates the type boundary for supported paged operations and yielded item inference.
packages/…/wrappers.test.tsDemonstrates the guarantees for auth setup, per-request credentials, transport cancellation and retries, error conversion, pagination, batching, encoding, and job polling.
packages/…/package.jsonShows the published package entry points, exported contract file, code generation command, and commands that build or regenerate the client.
packages/…/CHANGELOG.mdRecords public client and contract changes such as organization key creation, file updates, error behavior, pagination, and generated SDK refreshes.