---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://segmentstream.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Connections SDK

Declare a managed provider or a custom API and give workspace code a stable connection key.

## What you can build

- [Use a managed provider](https://segmentstream.com/docs/connections)

  Pick a preset, declare a key and authorize the provider in the deployed workspace.

- [Connect an API with a bearer token](https://segmentstream.com/docs/sdk/connections#declare-the-connection-keys)

  Declare a base URL and a credential field the operator can configure.

- [Import data through a connection](https://segmentstream.com/docs/import-existing-records)

  Handle pagination and store the upstream IDs so a batch can be retried.

## Choose a preset or custom API

In the workspace’s connections/ Python project, use the segmentstream-connections distribution and import segmentstream_connections. A preset supplies the provider contract. For a custom service, declare its API base URL and how the platform should attach credentials.

## Declare the connection keys

The first entry uses the Google Ads preset. The second declares a bearer-token API. Replace the example URL with your provider’s base URL. The Secret declaration gives the credential an input label. The actual token is configured after deployment.

connections/connections.py

```
from segmentstream_connections import ApiKeyConnection, Bearer, GoogleAdsConnection, Secret

connections = (
    GoogleAdsConnection(key="google_ads"),
    ApiKeyConnection(
        key="support", name="Support", provider="support",
        headers={"Authorization": Bearer(Secret(label="API token"))},
        apis={"api": "https://support.example.com/api/"}, default_api="api",
    ),
)
```

## Verify the deployed connection

Deploy the declaration, configure the support token in the console, then inspect the connection by key. For Google Ads, complete the provider authorization flow. Test a read of a known source record before adding a paginated import.

Terminal

```
segmentstream connection get support
segmentstream connection authorize google_ads
```

## Selected API methods and types

### Use the managed preset · `GoogleAdsConnection`

Google Ads account discovery and GAQL reporting, managed by SegmentStream. Declare a stable key, deploy, then authorize through the UI or CLI. Use \`\`get_connection(key).get_http_client()\`\` during execution. OAuth credentials, developer-token injection and refresh are owned by the backend.

```
class GoogleAdsConnection(_ManagedConnection):
    provider: ClassVar[str] = 'google_ads'
    available_scopes: ClassVar[tuple[str, ...]] = ('https://www.googleapis.com/auth/adwords',)
    name: str = 'Google Ads'
```

### Declare a custom API · `ApiKeyConnection`

HTTP access authenticated by static values, such as API keys or tokens. Each entry in \`headers\` or \`query\` maps the name the provider expects to a \`Secret(...)\` configured after deployment, or to \`secret_ref(...)\` for a shared workspace secret. A value that is not secret, such as an account id, is a \`Value(...)\`: it is configured the same way, and responses may contain it. The value is sent unchanged; wrap a header's secret in \`Bearer(...)\` to send \`\`Bearer \<value>\`\`, or in \`Scheme("Token", ...)\` for another scheme. For providers that read the value from the URL path, \`path\` maps one segment prefix to its secret: \`\`path={"bot": Secret()}\`\` sends \`\`\<api>/bot\<value>/\<request path>\`\`. The field key is the name in lowercase with hyphens and dots replaced by underscores, for example \`Client-Id\` -> \`client_id\`. Set \`public=True\` for an API with no authentication. Public connections must have no header, query or path credentials and are ready immediately after deployment. A value of \`apis\` may be an \`McpApi\` instead of a URL: a remote MCP server reached with the same credentials, limited to the tools it declares. For a provider that signs each request, such as Binance Pay, \`signing\` declares the headers and query parameters the backend computes for every request; see \`segmentstream_connections.signing\`. \`verification\` declares values the provider gives for checking what it sends, such as a webhook signing secret (\`\`whsec\_…\`\`) or a registration verify token, named in lowercase with underscores: \`\`verification={"webhook_signing_secret": Secret(label="Webhook signing secret")}\`\`, or \`\`uses("api_secret")\`\` for a secret the connection already holds. Members set them on the connection like its other values, and a webhook that names the connection checks its deliveries against one with \`\`input\`\`. Only the platform's checks read them: requests never carry them and workspace code never receives them. A connection whose verification values are unset still makes requests. A provider that only sends, such as one whose webhooks have no API behind them, declares verification values alone: no headers, no \`\`apis\`\`. Such a connection cannot be called, and it is configured once its values are set.

```
class ApiKeyConnection(HttpApis):
    type: ClassVar[Literal['api_key']] = 'api_key'
    key: str
    name: str
    provider: str
    public: bool = Field(default=False, strict=True)
    read_only: bool = Field(default=False, strict=True)
    headers: Mapping[str, SecretReference | Bearer | Scheme] = Field(default_factory=dict)
    query: Mapping[str, SecretReference] = Field(default_factory=dict)
    path: Mapping[str, SecretReference] = Field(default_factory=dict)
    apis: dict[str, str]
    default_api: str | None = None
    signing: Signing | None = None
    verification: Mapping[str, VerificationValue] = Field(default_factory=dict)
    validate_key(cls, value: str)
    validate_name(cls, value: str)
    validate_provider(cls, value: str)
    validate_headers(cls, value: Mapping[str, SecretReference | Bearer | Scheme])
    validate_query(cls, value: Mapping[str, SecretReference])
    validate_path(cls, value: Mapping[str, SecretReference])
    validate_verification(cls, value: Mapping[str, VerificationValue])
    validate_apis(cls, value: dict[str, str])
    validate_connection(self)
    credentials(self)
```

### Describe the required credential · `Secret`

A write-only input owned by the containing connection and field.

```
class Secret(SecretReference):
    type: Literal['secret', 'owned_secret'] = 'owned_secret'
    name: str = ''
```

[Connections](https://segmentstream.com/docs/connections)

[Read as Markdown ↗](https://segmentstream.com/docs/sdk/connections.md)
