Skip to content

Migrate to V2 of API #69

Open
Open

Description

@cincuranet
No description provided.

Activity

  1. self-assigned this
    on Jan 24, 2025
  2. andyyi commented on Apr 21, 2025

    @andyyi

    When to finish this?

  3. cincuranet commented on Apr 21, 2025

    @cincuranet
    CollaboratorAuthor

    There's no hard ETA.

  4. inlineHamed commented on May 29, 2025

    @inlineHamed

    This pull request implements api v2. it's not fully tested but is functional:
    #80

  5. Laurianti commented on Jul 9, 2025

    @Laurianti

    I'm using this temporary workaround:

    public class ApiV1ToV2DelegatingHandler : DelegatingHandler
    {
    	protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    	{
    		var baseAddress = new Uri($"{request.RequestUri.Scheme}://{request.RequestUri.Host}:{request.RequestUri.Port}/api/v2/");
    
    		var queries = HttpUtility.ParseQueryString(request.RequestUri.Query);
    
    		var tenant = queries["tenant"];
    		queries.Remove("tenant");
    
    		var database = queries["database"];
    		queries.Remove("database");
    
    		if (string.IsNullOrWhiteSpace(tenant) || string.IsNullOrWhiteSpace(database))
    		{
    			var httpClient = new HttpClient
    			{
    				BaseAddress = baseAddress
    			};
    
    			var authIdentityResponse = await httpClient.GetFromJsonAsync<AuthIdentityResponse>("auth/identity", cancellationToken);
    
    			tenant ??= authIdentityResponse?.Tenant;
    			database ??= authIdentityResponse?.Databases.FirstOrDefault();
    		}
    
    		var uriBuilder = new UriBuilder(request.RequestUri)
    		{
    			Query = queries.ToString()
    		};
    
    		request.RequestUri = new Uri(uriBuilder.Uri.ToString().Replace(baseAddress.ToString(), $"{baseAddress}tenants/{tenant}/databases/{database}/"));
    
    		var response = await base.SendAsync(request, cancellationToken);
    
    		if (request.RequestUri.AbsolutePath.EndsWith("/query"))
    		{
    			var originalContent = await response.Content.ReadAsStringAsync(cancellationToken);
    
    			var payload = JsonSerializer.Deserialize<Dictionary<string, object?>>(originalContent) ?? [];
    
    			payload["data"] = null;
    
    			var modifiedContent = JsonSerializer.Serialize(payload);
    
    			response.Content = new StringContent(modifiedContent, Encoding.UTF8, "application/json");
    		}
    
    		return response;
    	}
    }

    Here's an example of how it's used:

    var handler = new ApiV1ToV2DelegatingHandler
    {
    	InnerHandler = new HttpClientHandler()
    };
    
    var httpClient = new HttpClient(handler);
    
    var config = new ChromaConfigurationOptions("http://localhost:8000/api/v2/");
    
    var client = new ChromaClient(config, httpClient);
  6. kodlar commented on Aug 26, 2025

    @kodlar

    AuthIdentityResponse can you share this class content only missing part

  7. Laurianti commented on Sep 14, 2026

    @Laurianti

    Reposting from my personal account (the work account above is being retired), in case it is still useful:

    AuthIdentityResponse can you share this class content only missing part

    public class AuthIdentityResponse
    {
        [JsonPropertyName("user_id")]
        public required string UserId { get; set; }
        
        public required string Tenant { get; set; }
        
        public required string[] Databases { get; set; }
    }
  8. Laurianti commented on Oct 3, 2026

    @Laurianti

    ChromaDotNet.Client moves the client to the v2 API, with #80 and #82 (#84). The v1 API stays available for the servers that have only it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions