Skip to content

Conversation

@jhcipar
Copy link

@jhcipar jhcipar commented Sep 4, 2025

This PR makes a small change to ServerlessEndpoint resources and the ResourceManager classes.

Currently, after a resource is created, the class that defines it does not have a persistent identifier for its associated entity in Runpod. For example:

gpu_resource = ServerlessEndpoint()

gpu_resource.id # 🔴  this fails

@jhcipar jhcipar requested review from deanq and pandyamarut September 4, 2025 17:55
@jhcipar jhcipar marked this pull request as ready for review September 5, 2025 00:28
Copy link
Member

@deanq deanq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This becomes an anti-pattern. Under ServerlessResource class, you'll see that the @property decorated functions check for a self.id before proceeding. The pattern is to make sure the endpoints are either deployed or known to be existing per its id. I saw in your example that what you really needed was a way to generate the open_ai URL for the endpoint via gpu_server_url = f"https://api.runpod.ai/v2/{gpu_serverless_endpoint.id}/openai/v1"

Here's my suggestion then. Under ServerlessResource class, create this property function...

   # self.url is already taken for Console URL

   @property
   def endpoint_url(self) -> str:
       base_url = self.endpoint.rp_client.endpoint_url_base
       return f"{base_url}/{self.id}"

This could be done cleanly from the SDK itself, but we'll do that when we address the SDK overhaul in the near future.

You can then refer to it by gpu_serverless_endpoint.endpoint_url as

gpu_server_url = f"{gpu_serverless_endpoint.endpoint_url}/openai/v1"

...I'll address your example PR at that repo

@jhcipar
Copy link
Author

jhcipar commented Sep 9, 2025

@deanq I think I misunderstood your original comment. Part of the motivation for this is that the ids (including urls) for resources aren't available via the config objects at runtime. I think that suggestion (and all of those properties) will still throw an error.

This happens because the deploy methods for config objects return an endpoint and store it, but don't actually assign any of the endpoint information back to the config object. So even after creating a config object and deploying resources from it we can't access any of the deployed resources from the returned config object.

I think what's happening is that in a serverless endpoint we create the runtime endpoint object from the GraphQL client here and then the resource manager stores the object here. But at no point do we assign the endpoint.id back to the config object.

example: this will always fail

@remote(cpu_live_serverless)
def foo():
  return "bar"

await foo()
print(cpu_live_serverless.url)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants