Skip to content

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

GetStream .NET SDK

This is the official .NET SDK for GetStream's Feeds API.

For detailed setup instructions, see Example.

Current version

v17 is the current major version of the getstream-net package. The latest release is on the releases page. Docs: Chat, Video, Feeds and Moderation.

Build with AI coding agents

Stream's agent skills give AI coding agents such as Claude Code, Cursor and Codex current knowledge of Stream's SDKs and docs. Install the Stream CLI and the skills:

curl -fsSL https://getstream.io/cli.sh | bash
getstream init

Then ask the /stream skill, for example:

/stream how do I create a user token with the .NET SDK?

To let your agent look up Stream API endpoints and query your Stream apps, add Stream's MCP server. In Claude Code:

claude mcp add --transport http stream https://mcp.getstream.io/mcp

Upgrading from v16?

See v16 → v17. HTTP JSON for API fields is unchanged. string fields became enum structs. Campaign responses, removed request types, and DateTime JSON changed.

Migrating from stream-chat-net?

If you are coming from stream-chat-net, we have a detailed migration guide with side-by-side code examples for every common Chat use case.

See the Migration Guide.

✨ With an AI coding agent, the /stream-backend skill ports your integration call by call: it inventories every legacy call site, keeps behavior identical where it can, and lists by file and line the calls that change or need your decision, for you to review before you ship. It comes with the agent skills. See stream-backend.

Environment Setup

For Development

export STREAM_API_KEY=your-api-key-here
export STREAM_API_SECRET=your-api-secret-here

For CI/CD

This repository uses the API key zta48ppyvwet for continuous integration testing.

Makefile Commands

The project includes a Makefile for common development tasks:

# Run the sample application
make sample

# Run unit tests (no credentials needed)
make test

# Run the tests that talk to a live Stream app
make test-integration

# Additional commands available in Makefile
make build     # Build the project
make clean     # Clean build artifacts

A fixture in the Integration category talks to a live Stream app and needs credentials. TestBase carries the category and NUnit inherits it, so deriving from it is enough. make test excludes the category; make test-integration runs only it.

CI follows the same split:

When What runs Gates
Pull request format check, both builds, make test, package build yes, 🧪 Tests
Daily at 13:00 UTC make test-integration no, a red run opens an issue
Release PR merged nothing on the default branch, the unit lane on N.x N.x only

Structure

The SDK is organized into several key components:

  • src/ - Core SDK implementation
    • Client.cs - Main HTTP client with authentication and request handling
    • CommonClient.cs - Shared client functionality and utilities
    • CustomCode.cs - Custom implementations and extensions
    • Feed.cs - Feed entity and core functionality
    • Several OpenAPI-generated files:
      • FeedsV3Client.cs - Generated client with all feeds API methods
      • models.cs - Generated response models
      • requests.cs - Generated request models
  • tests/ - Comprehensive test suite
    • FeedClientTests.cs - Unit tests for feed client
    • FeedIntegrationTests.cs - Integration tests
    • FeedTests.cs - General feed functionality tests
  • samples/ - Example applications and usage demos
    • ConsoleApp/ - Console application demonstrating basic usage

Development

The SDK development workflow:

  1. Core Components

    • Manual implementation of core client functionality
    • Custom extensions and utilities for .NET-specific features
    • Comprehensive test coverage for all components
    • OpenAPI-generated code for complete API coverage
  2. Testing

    • Unit tests for individual components
    • Integration tests for end-to-end functionality
    • Sample applications for usage demonstration
  3. Build and Run

    • Use Makefile commands for common tasks
    • Regular testing and validation
    • Continuous integration checks

The SDK follows .NET best practices and conventions while providing a clean, maintainable codebase for GetStream's Feeds API integration.

Structured Logging

Pass Logger on StreamOptions (or ClientBuilder.Logger(...)) to receive structured events via Microsoft.Extensions.Logging.ILogger. No logger set means no output; the SDK never changes the logger's configured level. Four canonical events, matching the cross-SDK logging spec:

Event (dotted name, message prefix) Level Emitted
client.initialized INFO Once, at BaseClient construction
http.request.sent DEBUG Before every request is sent
http.response.received DEBUG After any HTTP response, including 4xx/5xx
http.request.failed ERROR or DEBUG ERROR on a final transport failure (no HTTP response received); DEBUG instead, with a {RetryAttempt} field, on any attempt that Retry will retry. Never emitted for a final/non-retried 429 (already covered by http.response.received).

.NET's ILogger uses PascalCase message-template placeholders ({Method}, {StatusCode}, ...). Each maps to a canonical snake_case field name used identically across all GetStream SDKs:

Event Placeholder Canonical field
client.initialized {SdkName} stream.sdk.name
{SdkVersion} stream.sdk.version
{MaxConnsPerHost} stream.client.max_conns_per_host
{IdleTimeoutSeconds} stream.client.idle_timeout_seconds
{ConnectTimeoutSeconds} stream.client.connect_timeout_seconds
{RequestTimeoutSeconds} stream.client.request_timeout_seconds
{GzipEnabled} stream.client.gzip_enabled
{UserHttpClient} stream.client.user_http_client
{LogBodies} stream.client.log_bodies
http.request.sent {Method} method
{Path} path
{Query} query (redacted)
{Body} body (redacted; only present when LogBodies=true)
http.response.received {Method} method
{Path} path
{StatusCode} status_code
{BodySize} body_size (bytes)
{DurationMs} duration_ms
{Body} body (redacted; only present when LogBodies=true)
http.request.failed {Method} method
{Path} path
{ErrorType} error.type (transport failures only; never present on a retried 429 — see below)
{DurationMs} duration_ms (transport failures only)
{Message} error.message (redacted; transport failures only)
{RetryAttempt} retry.attempt (1-indexed; present only when this attempt will be retried)

error.type is one of connection_reset, timeout, dns_failure, tls_handshake_failed, unknown (see GetStreamTransportException.ErrorType) — a closed transport-only enum. A retried HTTP 429 has no transport error at all, so its http.request.failed DEBUG line carries only {Method}, {Path}, {RetryAttempt}: never {ErrorType}.

Redaction (always on, no opt-out): query values for api_key/api_secret/token (case-insensitive) become <redacted>; top-level JSON body keys api_secret/token/password become <redacted> (shallow, key names are preserved). No header values are ever logged. error.message is additionally scrubbed for any api_key=/api_secret=/token= value appearing anywhere in the free-form transport-exception text.

Bodies are not logged by default. Set StreamOptions.LogBodies = true (or ClientBuilder.LogBodies(true)) to opt in; body content is still key-redacted as above. Enabling it emits exactly one WARN line at construction.

Retry Policy

Auto-retry is opt-in and off by default: with no Retry configured, the client performs exactly one attempt and errors surface unchanged.

var client = new StreamClient(new StreamOptions
{
    ApiKey = "...",
    ApiSecret = "...",
    Retry = new RetryConfig { Enabled = true, MaxAttempts = 3, MaxBackoff = TimeSpan.FromSeconds(30) },
});

When enabled:

  • Only GET/HEAD requests are retried. Writes (POST/PUT/PATCH/DELETE) never are.
  • Only HTTP 429 (rate limit) and transport-layer failures (connection reset, timeout, DNS, TLS) are retried; any other 4xx/5xx is never retried.
  • A 429 marked unrecoverable by the backend is never retried.
  • MaxAttempts is the total attempt budget including the initial request (default 3: 1 initial + 2 retries).
  • The delay before each retry honors a Retry-After response header when present, clamped to MaxBackoff; otherwise it's full jitter over [0, min(MaxBackoff, 2^attempt seconds)].

Regeneration

The client regenerates itself on every chat production release:

  1. chat attaches its openapi generator to the release and publishes the matching openapi-vX spec release in protocol.
  2. protocol notifies this repo, and the Regenerate workflow opens one PR from regen/auto, titled feat: regenerate client from openapi-vX. Its BEGIN_COMMIT_OVERRIDE block lists the changelog lines.
  3. Once the required checks pass and the Regen integration run passes on the PR's head commit, the PR merges itself, and release-please adds those lines to the Release PR. Merging the Release PR ships, as described below.

A regen PR waits for a human when its changelog carries a BREAKING CHANGE: footer, when the Breaking changes check finds an approved breaking change in the new spec, or when a required check fails. For each approved breaking change with wire lines or getstream-net sdk lines, the regen writes BREAKING CHANGE: footers from the lines chat allowlisted and titles the PR feat!:, so the check passes and the PR only waits for a human to merge it. A ticket chat approved for getstream-go only has no .NET lines, so the check fails until a human names it in the PR body, also on a feat!: PR. The Breaking changes check also compares the public API of every PR, hand-written code included, against its base with ApiCompat, and fails on an incompatible change unless the title has ! or the PR is labelled sdk-not-breaking. A regen PR can fail this comparison too, when a generator change alone breaks a caller; it then waits for a human, who handles it as one of the breaking-change cases below. Only getstream-sdk-bot can push to regen/**.

Manual cases

  • Regenerate now: run Regenerate from the Actions tab with an openapi-vX tag, or leave it empty for the latest. Locally, SPEC_TAG=openapi-vX ./generate.sh does the same with the generator built from a ../chat checkout at that tag.
  • A breaking change that breaks this SDK: when the regen titled the PR feat!:, review its footers. It moves on to each newer spec until you rename the PR or edit its body, which keeps it on the spec you judged. Otherwise add ! to the PR title, and before END_COMMIT_OVERRIDE add a blank line and BREAKING CHANGE: <what breaks for customers>. Then merge it yourself in a breaking-change window, with a MIGRATION_vX_to_vY.md guide.
  • An approved breaking change that does not break this SDK: label the PR sdk-not-breaking and name each ticket the check lists in the PR body. When the regen titled it feat!:, also drop the ! and delete the entries that carry a BREAKING CHANGE: footer. The next Regenerate run merges it, daily at 06:23 UTC or when you start one.
  • Failed integration tests: the Regenerate run reruns a red or cancelled Regen integration run by itself for up to three attempts, and merges the PR when one passes. If the third attempt is red too, it pings the group: fix the cause or rerun it again; a pass merges the PR. If no run started for the PR's head commit, start Regen integration on regen/auto from the Actions tab.
  • Rewrite a changelog line: edit the BEGIN_COMMIT_OVERRIDE block in the merged PR's body, then run the Release workflow to rebuild the Release PR. Keep ticket IDs out of PR titles, because a title becomes a changelog line.

Release Process

Releases are driven by release-please.

  • Merge PRs to master with conventional-commit titles, using Squash and merge. The title becomes the commit subject and decides the next version: feat: is a minor, fix: and perf: are a patch, feat!: or <type>(scope)!: is a major. Other types (chore, ci, docs, test, refactor) ship nothing.
  • release-please keeps a Release PR open with the version bump in src/stream-feed-net.csproj and CHANGELOG.md. Never edit <Version> by hand.
  • Its runs are created held at action_required until someone clicks Approve and run, because release-please opens the PR with GITHUB_TOKEN. The unit lane then reports skipped and 🧪 Tests goes green without running a test. The skip only applies while the diff is nothing but what release-please writes, down to the version line in each version file, so a code or dependency change pushed onto a Release PR by hand runs the unit lane like any other PR.
  • Merging the Release PR creates the tag and the GitHub Release on that merge commit and pushes the package to NuGet, with no further test run: the Release PR adds only the version bump and changelog to an already-tested master. A hotfix release from N.x runs the unit lane first, since its commits were pushed without a PR. A tag, a GitHub Release and a NuGet push cannot be withdrawn. The publish step builds and packs, so a build that does not compile fails there after the tag exists; the fix ships under the next version, since publish_tag rebuilds the same tag.

To retry a NuGet push that failed after the release was tagged, use "Re-run failed jobs" on that workflow run. Once GitHub has retired the run, dispatch Release from master with publish_tag set to the tag (for example v16.1.1), which packs and pushes that tag without touching release-please. If the release job fails after the Release PR merged, the release stays pending and every later push logs a warning naming the commit to go back to, rather than failing.

To force a specific version, type Release-As: X.Y.Z in the commit message box of the squash dialog when merging a PR; the PR description is not copied there. To hotfix while master carries unreleased work, branch N.x from the last tag, cherry-pick the fix, and merge the Release PR that release-please opens against that branch.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages